Search code examples
jqueryjquery-selectorsprototypejseach

Jquery $.each selector


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

Is there an equivalent in prototype?


Solution

  • $.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
    });