Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery $.each selector

I would like to know what $.each() stands for in jquery,
What is it selecting?

Is there an equivalent in prototype?

like image 983
Steffi Avatar asked Aug 10 '10 15:08

Steffi


1 Answers

$.each() isn't selecting anything. It is just a utility to iterate over a collection.

When you do:

$('someSelector').each(function() {
    // do something
});

jQuery is internally calling:

jQuery.each( this, callback, args );

...with this representing the matched set.

http://github.com/jquery/jquery/blob/master/src/core.js#L231

You could just as easily call it yourself manually.

jQuery.each( $('someSelector'), function() {
    // do something
});
like image 79
user113716 Avatar answered Sep 27 '22 17:09

user113716