I made somesimple js code but result is unexpected. how this is possible?
var n = $("#mGrid tbody tr[class*='success']");
console.log(n.length);
for (var i in n)
{
console.log("x");
}
console
2
202 x
That means 202 times x was printed in the console. When you are using a for..in loop over an object, the enumerable property of the particular object will be iterated until the end of prototype chain of it.
Your object has 202 numerable properties both own and prototype properties.
For iterating over the jquery object, you can use .each like below,
e.each(function(){
//$(this) the current element on the iteration.
});
Still if you want to use a for loop, then you have to do like below,
for (var i=0,i< n.length;i++) {
console.log("x");
}
.each approach that I given above.
.each()to loop through all the DOM nodes selected byn.