samedi 3 janvier 2015

jQuery find inside selector


Looping through divs, i'm tring to write a selector to get the uls, and do something for each of them.


My HTML (simplified) looks like this:



<div class="foo">
<ul>
</ul>
<ul>
</ul>
...
</div>
<div class="foo">
<ul>
</ul>
<ul>
</ul>
...
</div>

...


after this:



variable=$(.foo);


that of course works fine, now i'm tring to do something like



for(var k=0;k<variable.length;k++){
variable[k].find('ul').doSomethingWithThese
}


but the selector is somehow wrong.

Even if my attempts were made on a simplified code, like the one in the example, the code is much more complex than this,

(inside my divs there is a lot more going on, and i'm building a loop with a map() function that for every div extracts something and concatenates with something else, and prints everything somewhere else...)

so please understand i can't just go like $(".foo > ul"), and even if i could i want to understand why my other attempts fail.



I tried every thinkable variant in the last 3 hours, including: using children() instead of find(), using get(0) insted of [0], using get(0) or [0] after ('ul') (to try at least to get the first ul),

using $variable, $.(variable), ($.('ul')), ($('ul')), using each() instead of a for loop, creating variables for everything, all the combinations possible of all of the above, google, stackoverflow, api.jquery.com...



than i tried even more simplified:



variable[0].children('ul')
variable[0].children('ul')[0]


and all the variants, and still no luck...





Aucun commentaire:

Enregistrer un commentaire