Reputation: 1747
I have a list structure that looks as follows:
<ul id="BirdMother" class="parent">
<ul class="child">
<li class="baby">
</ul>
<ul class="child">
<li class="baby">
</ul>
<ul class="child">
<li class="baby">
</ul>
</ul>
I want to select all the baby
list items in an iterative manner to use in a function that looks like this: function feedBabies(babyList)
.
How can I select all the baby
items?
Edit: What if there are multiple baby items in the page and I only want the babies from a certain parent list. Eg: Only Bird babies. (Edited the code above).
Upvotes: 2
Views: 99
Reputation: 2498
Just use class selector
var babyList = $(".baby");
feedBabies(babyList);
For certain parent
var babyList = $("#BirdMother .baby");
feedBabies(babyList);
Upvotes: 4
Reputation: 2464
Here you have solution
$("#useThisList > ul").each(function(){
alert($(this).html());//this will give you html
alert($(this).text());// this will give you text in li
});
Upvotes: 0