The
Each method is simply delegated: The jquery object is passed as the first argument to the each method of jquery. In other words: jquery provides a method call for each of the child elements in the object provided by the parameter one. The jquery object provides each method to call the child elements within jquery individually
Args is to internal usage only
Each:function (object, callback, args) {
var name, i = 0,
Length = Object.length,
Isobj = length = = Undefined | | Jquery.isfunction (object);
if (args) {
if (isobj) {
For (name in object) {
if (callback.apply (object[name], args) = = False) {
Break
}
}
} else {
for (; i < length;) {
if (callback.apply (object[i++], args) = = False) {
Break
}
}
}
A special, fast, case for the most common use of each
} else {
if (isobj) {
For (name in object) {
if (Callback.call (object[name, name, object[name]) = = False) {
Break
}
}
} else {
for (var value = object[0];
I < length && Callback.call (value, I, value)!== false; Value = Object[++i]) {}
}
}
return object;
},
An example from the jquery official found
<!doctype html>
<style>
div {color:blue;}
div#five {color:red;}
</style>
<script src= "Http://code.jquery.com/jquery-1.5.js" ></script>
<body>
<div id= "One" ></div>
<div id= "Two" ></div>
<div id= "three" ></div>
<div id= "Four" ></div>
<div id= "Five" ></div>
<script>
var arr = ["One", "two", "three", "four", "five"];
var obj = {one:1, two:2, Three:3, Four:4, five:5};
Jquery.each (arr, function () {
$ ("#" + This). Text ("Mine are" + this + ".");
Return (This!= "three"); Would stop running after "three"
});
Jquery.each (obj, function (i, Val) {
$ ("#" + i). Append (document.createTextNode ("-" + val));
});
</script>
</body>
From the example above you can see that return false in the callback function, most JQ methods are the same
===================================
Returning ' false ' will stop the loop (like using ' break ' in an ordinary loop).
Returns ' true ' to the next loop (like using ' Continue ' in an ordinary loop).