$.each(".indent", function(index){
does not iterate over the elements of $('.indent') , but over the string ".indent" with a length of 7 characters.
See link
More detailed explanation based on jQuery source code :
jQuery first checks to see if the first obj parameter (here is your string) length :
var ... length = obj.length, isObj = length === undefined || jQuery.isFunction( obj );
Your string having length (and not a function) isObj is false .
In this case, the following code is executed:
for ( ; i < length; ) { if ( callback.call( obj[ i ], i, obj[ i++ ] ) === false ) { break; } }
So, given the function f , the following code
$.each(".indent", f);
equivalently
for (var i=0; i<".indent".length; i++) { var letter = ".indent"[i]; f.call(letter, i, letter); }
(you can write letters with var f = function(i,v){console.log(v)}; or recall one of the subtleties of call with var f = function(){console.log(this)}; )
Denys SΓ©guret Nov 30 '12 at 15:51 2012-11-30 15:51
source share