jquery pros - get id of element clicked

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

jquery pros - get id of element clicked

Post 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);
 	});
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

ok... got it.. its as simple as this.id
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: jquery pros - get id of element clicked

Post 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);
 	});
(#10850)
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Correct....
Post Reply