I’m trying to use for..in loop to select the objects within a variable and it doesn’t show up the necessary Li objects.
var mUlLi = $(mUl).find('>li'); //select all li's in main Ul
var listLength = $(mUlLi).length;
if(listLength >0 ){
/*for(i=0;i <listLength; i++) {
console.log(mUlLi[i]); // works fine show the li objects
}*/
for(var obj in mUlLi) {
console.log(obj); // show's diff objects
}
}
How can i fix this ?
jQuery has an
each()that does the same thing.If you used a
for inon a jQuery object, you’d also be looping through the jQuery methods and properties.However, if you really want to do a
forloop on the elements you got from that jQuery (because you didn’t want to useeach()), then do it directly: