Hi, I would like to know what $.each() stands for in jquery, What is it selecting?
Is there an equivalent in prototype?
Thanks
Hi, I would like to know what $.each() stands for in jquery, What is it selecting?
Is there an equivalent in prototype?
Thanks
jQuery uses each
in two ways:
The .each() method is designed to make DOM looping constructs concise and less error-prone. When called it iterates over the DOM elements that are part of the jQuery object. Each time the callback runs, it is passed the current loop iteration, beginning from 0. More importantly, the callback is fired in the context of the current DOM element, so the keyword this refers to the element.
The $.each() function is not the same as .each(), which is used to iterate, exclusively, over a jQuery object. The $.each() function can be used to iterate over any collection, whether it is a map (JavaScript object) or an array. In the case of an array, the callback is passed an array index and a corresponding array value each time. (The value can also be accessed through the this keyword.)
I think you should rather look at
From the documentation
The $.each() function is not the same as .each(), which is used to iterate, exclusively, over a jQuery object. The $.each() function can be used to iterate over any collection, whether it is a map (JavaScript object) or an array. In the case of an array, the callback is passed an array index and a corresponding array value each time. (The value can also be accessed through the this keyword.)
$.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
});