I am trying to follow my steps with jQuery, but it is hard for me to figure out how to find the list of children from the parent div. I'm used to working with ActionScript 2 and ActionScript 3, so I might be mistaken in some concept, for example, as the best way to randomize a sequence of div elements using jQuery!
I have this simple piece of HTML code:
<div class="band"> <div class="member"> <ul> <li>John</li> <li>Lennon</li> </ul> </div> <div class="member"> <ul> <li>Paul</li> <li>McCartney</li> </ul> </div> <div class="member"> <ul> <li>George</li> <li>Harrison</li> </ul> </div> <div class="member"> <ul> <li>Ringo</li> <li>Starr</li> </ul> </div> </div>
I tried to do this as map .member divs in a single array, and then changed the sort order, but to no avail.
function setArrayElements (element_parent) { var arr = [];
when I tried to notify element_parent [0] , I thought to get the first child of my .member div list, but it is not.
if I make a warning with element_parent [0] .innerHTML , I see that:
<div class="member"> <ul> <li>John</li> <li>Lennon</li> </ul> </div> <div class="member"> <ul> <li>Paul</li> <li>McCartney</li> </ul> </div> <div class="member"> <ul> <li>George</li> <li>Harrison</li> </ul> </div> <div class="member"> <ul> <li>Ringo</li> <li>Starr</li> </ul> </div>
Why? How can I do to get exactly one of these members?
<div class="member"> <ul> <li>Paul</li> <li>McCartney</li> </ul> </div>
I'm sure this should be easy, but I just don't know how :(
please, help
thank
Vittorio
EDIT:
Thank you for your stability and the various ways you can get your children. I will mark these paths for the future!
I tried these methods, but it seems I could not get the whole div (please let me know if I do something, it could be too much!).
I want to get this content:
<div class="member"> <ul> <li>Ringo</li> <li>Starr</li> </ul> </div>
but with one of the methods like $ ("div.band div.member: eq (2)") or other useful ways, I get the following:
alert ($('div.band div.member')[0]); /* result <ul> <li>Ringo</li> <li>Starr</li> </ul> */
so is there a way to get the div .member container in my node?