I'm trying to do my frist steps with jQuery but I have some trouble to understand how to find a list of child elements from a div parent element. I'm used to work with ActionScript 2 and ActionScript 3 so i could mistake some concept, like what is the better way to randomize a sequence of div elements with jQuery!
I have this simple portion 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 have attempted some way to do that like map .member divs in one array and then changing the sort order but without success.
function setArrayElements (element_parent) { var arr = []; //alert (element_parent[0].innerHTML); for (var i = 0; i < element_parent.children().length; i ++) { arr.push (element_parent[i].innerHTML); } } setArrayElements($(".band"));
when i attempted to alert element_parent[0] i thought to get the first child of my .member list of divs but it isn't.
if i make an alert 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 the members like this?
<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
thanks
vittorio