What is the difference between this:
$.each($(\'#myTable input[name=\"deleteItem[]\"]:checked\').do_something());
and this:
from http://api.jquery.com/jQuery.each:
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.
There is no functional difference. Every jQuery object owns a .each()
method inherited from jQuery.fn
. By calling this object method
, jQuery already knows which Array (-like object)
to iterate over. In other words, it loops over the indexed propertys
from the current jQuery object.
$.each()
on the other hand is just a "helper tool" which loops over any kind of Array
or Object
, but of course you have to tell that method which target you want to iterate.
It'll also take care of you whether you pass in an Array or object, it does the right thing using a for-in
or for loop
under the hood.