Each takes a function as a parameter. Generally people just pass in an
anonymous function (e.g. $('.oneclass').each(function(i) {}); ) but there is
no reason you can't pass in a function you defined previously (e.g.
$('.oneclass').each(fmoveCodeToImg); ).

So, each has a function. When it runs, it loops through the array of
elements and runs the function on each of them. This means that within the
context of the function 'this' is a DOM element. Each also passes the array
index of the element to the function as the first argument, which most
people just call i.

$(".oneclass").each(function(i) {
 alert("Element "+i+" is "+this.toString());
});

Blair

On 12/19/06, Abel Tamayo <[EMAIL PROTECTED]> wrote:

Wow, thanks everyone for the superfast response.
Ok, as Brandon suggested, the right way was using

$('.oneClass').each(function() { moveCodeToImg(this); });

wich I had already tried but didn't realize i had to change some things in
the function used since i was recycling it and the parameters and variables
returned where all new (also, don't see why you have to use the reserved
word function() when moveCodeToImg is already a function, the kind of
paramenter that each(function) expects, but anyway). Now I'm intrigued
about Mike's answer:

$('.oneClass').each(moveCodeToImg);

since I don't remember reading about sintax like that in the documentation
of jQuery. How come you can call a function without parentheses and the
parameters it expects and how do you rearrange a function to receive an
"index" or where can i read more about this nomenclature?

Thanks again. Great community.

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/



_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to