views:

155

answers:

3
$("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.

A: 

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

John Burton
I need to get index.
Shore
+2  A: 

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

warpech
Is Query(this) the alias of $(this)?
Shore
Yes they are the same
John Burton
'jQuery' - yes. I always use it to avoid collision with other libraries using $ function.
warpech
@warpech: You could just do `$j = jQuery.nonConflict();` so you won't have to write "jQuery" every time...
peirix
+1  A: 

Use JQuery's index function

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