How to make jQuery methods work in a for loop?
I know I can use the jQuery .each() function (and it works fine), but the
performance is too sluggish. So I want to use a for loop and have the
jQuery methods available inside it. For example:
var anArray = $('#somediv').children(); // it has a lot of children
for(i=0;i<anArray.length;i++) { // or for(i=anArray.length;i--;)
anArray[i].addClass('sample_class'); // and a bunch of other stuff
};
Right now the browser throws this error:
Uncaught TypeError: Object #<HTMLDivElement> has no method 'addClass'
Think it had something to do with the jQuery wrapper $() I know I read the
solution somewhere a while ago, but I'm just unable to retrace it.
No comments:
Post a Comment