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
$(".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.
With jQuery object (not necessary)
$(".vote").click(function(){
var id = $(this).attr('id');
});
Without jQuery object (faster)
$(".vote").click(function(){
var id = this.id;
});
i think this also work
$("body").on("click",".vote",function(){
var id = this.id;
});