By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,616 Members | 2,026 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,616 IT Pros & Developers. It's quick & easy.

How Jquery knows that "intIndex" is the loop iteration index?

100+
P: 103
How Jquery knows that "intIndex" is the loop iteration index?

The example, which i do not understand is from: http://www.bennadel.com/blog/534-the-beauty-of-the-jquery-each-method.htm

Expand|Select|Wrap|Line Numbers
  1. // Loop over each hottie.
  2. $( "#girls a.hottie" ).each(
  3.  
  4.     // For each hottie, run this code. The "indIndex" is the
  5.     // loop iteration index on the current element.
  6.     function( intIndex ){
  7.  
  8.         // Bind the onclick event to simply alert the
  9.         // iteration index value.
  10.         $( this ).bind (
  11.             "click",
  12.             function(){
  13.                 alert( "Hottie index: " + intIndex );
  14.             }
  15.             );
  16.  
  17.     }
  18.  
  19.     );
  20.  
Jun 16 '15 #1
Share this Question
Share on Google+
3 Replies


Dormilich
Expert Mod 5K+
P: 8,639
How Jquery knows that "intIndex" is the loop iteration index?
because it puts the index there.
Expand|Select|Wrap|Line Numbers
  1. // e.g. jQuery 1.11.1 line #383
  2. value = callback.call( obj[ i ], i, obj[ i ] );
Jun 16 '15 #2

100+
P: 103
THE ANSWER IS IN OFFICIAL DOCUMENTATION:
https://api.jquery.com/index/

The variable in index(variable) function refers to the index of current element.
Jun 16 '15 #3

100+
P: 103
Thank you Dormilich.
Jun 16 '15 #4

Post your reply

Sign in to post your reply or Sign up for a free account.