benhowdle89 benhowdle89 - 4 months ago 13
jQuery Question

jQuery find ID of clicked button by class

I have numerous buttons on my page with the same class names. However these buttons have different ID's. How do i do this:

$(".vote").click(function(){
var id = $(this).{ID OF CLICKED BUTTON};
});


How can i make this pseudo code work?

Thanks

Answer
$(".vote").click(function(){
     var id = this.id;
});

The ID is accessible directly from the element. There's absolutely no need to use a jQuery method.