jQuery find ID of clicked button by class jQuery find ID of clicked button by class jquery jquery

jQuery find ID of clicked button by class


$(".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; });