I am trying to find all li within ul
if I do
console.log(element);
I get the ul element output in firebug.
If I console.log(element[0]); I get undefined.
Now to try to find all li within ul I do:
$('li', element).each(function (index) {
console.log(index);
});
But my index never gets outputed.
If I do:
$('li', element[0]).each(function (index) {
console.log(index);
$(this).data('previousIndex', index);
});
I get too many index count outputed to my console. My ul only has 3-4 li but I get some false count outputed.
Can anybody tell me my mistake?
EDIT:
To give more idea I am using sortable plugin. This is my firebug output when I do a children(). I am not sure why is this happening.

I assume
elementis still the DOM element<ul>and not a jQuery object. Because if it were,element[0]should not be undefined.So to operate jQuery on the
element, wrap it in jQuery first then usechildren('li')to get immediate children<li>orfind('li')to get all descendant (nested)<li>