Is this possible? For me to get the eq()
value? For example, if I click the li:eq(2)
, var x
will become 2
. Here's the code.
$('#numbers ul li').click(function(){
x=$(this).eq().val();
alert(x);
});
The .index()
what is this? method will do it.
$('#numbers ul li').click(function() {
var self = $(this),
index = self.index(),
text = self.text();
alert(text + ' ' + index);
});
The answer above is wrong. Index provides a relative value with respect to its siblings. Hence, the value is expected to change.
It should be something like
$('.someClass').click(function(){
var that_ = this;
// your logic for this function
....
....
var currentIndex = $('.someClass').index(_that);
});
eq<>
index:
scount=$(selector).length;
for(i=0; i<scount; i++){
$("selector:eq("+i+")").attr("eq",i);
}
$("selector").click(function(){
alert($(this).attr("eq"));
});