Question

$("span.ws_label").click(function() {

})

By selector "span.ws_label" there are 5 elements selected,

when one of them is clicked,

how to know which one actually?

EDIT

I must get the index or its id,$(this) is no use to me.

Was it helpful?

Solution

This is my trick:

var i = jQuery(this).prevAll().length;

(i equals the number of sibling nodes before this node)

see: http://docs.jquery.com/Traversing/prevAll

OTHER TIPS

Use JQuery's index function

 $("span.ws_label").index(this);

You can use $(this) inside the function. It's not an index number but it does refer to the element being clicked,

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top