Page 1 of 1

jquery pros - get id of element clicked

Posted: Sun Oct 28, 2007 12:32 pm
by GeXus
I have a list of items, that have the same class... I'd like to have a click event on that class, then get the id of the element clicked.... any idea how I would do that?

I've tried this, but no luck..

Code: Select all

     $(".categoryList").click(function () {

     		var id = this.attr("id");
     		alert(id);
 	});

Posted: Sun Oct 28, 2007 1:00 pm
by GeXus
ok... got it.. its as simple as this.id

Re: jquery pros - get id of element clicked

Posted: Sun Oct 28, 2007 3:10 pm
by Christopher
So people reading this thread can understand clearly, the solution you found was?

Code: Select all

     $(".categoryList").click(function () {

     		var id = this.id;
     		alert(id);
 	});

Posted: Mon Oct 29, 2007 10:41 am
by GeXus
Correct....