Hi Chris,
Short answer is that "index" is just an argument generated by the
"each()" function to mark objects that match the criteria we set...
it starts at 0 and increments according to what it finds. "index"
could be changed to anything we like, as it is only for the purpose
of passing a reference to the function.
Karl's whole code was:
$("a.open_button").each(function(index) {
$(this).click(function() {
$('div.section:eq(' + index + ')').slideToggle(1200,function() {
complete(index);
});
return false;
});
});
What we are telling jQuery to do here, in layman's terms is:
OK jQuery - you are looking for <a> tags of the class "open_button"
Every time you find one, pass a reference to its position in the
matched set by using "index" (which starts at 0 and goes up from there)
Set its "click" method to do the following:
Find the <div> of the class "section" whose position matches "index"
in all the <div class="section"> objects you find. Open it if its
closed, close it if its open.
When the slide is finished, call the function "complete" and let it
know which <div> has finished sliding by passing "index" as an argument.
And that's it.
In practical terms, suppose we have:
<a class="open_button" href="#">Open Section 1</a>
<div class="section>Some stuff in here</div>
<a class="open_button" href="#">Open Section 2</a>
<div class="section>Some more stuff in here</div>
the "each()" function will "see" that there are 2 <a
class="open_button"> objects, and so would pass index = 0, index = 1
in our function. Because there are also 2 <div class="section">
objects, each <a> will target the corresponding <div>
hope that makes some sense.
SJ
On 20 Jan 2007, at 15:42, Christopher Jordan wrote:
Steve,
The power of course lies in the statement $('div.section:eq(' + index
+ ')') - now all I need to do is have <a class="open_button> and
below
it <div class="section"> - no numeric identifiers, as jQuery is doing
the work iterating through the array of matching objects.
What is 'index'? Is it an in-built variable?
Cheers,
Chris
--
http://cjordan.info
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/