From the documentation, here's an example of using index():
$("div").click(function () {
var index = $("div").index(this);
$("span").text("That was div index #" + index);
});
I don't understand why we must duplicate the selector.
Why can't we replace the third line of code with the following?:
var index = $(this).index(this);
I.e, why can't we use $(this)?
What does the difference between the selector before .index and its argument?
Can I specify something different in place of the second $("div"),
and what purpose what that serve?
Thank you shedding light on this. Just when I think I've got jQuery
understood, it surprises me.
Totally confused ~