javascript - jQuery event fires for every selected element -
i have few buttons i'm wanting bind events to. have same css class select them class , bind event on mouseup. problem when click on 1 button function called once per button instead of once.
$('.btn').mouseup(function() { console.log('fired'); });
use on().
$(".btn").on("click", function(){ alert( $(this).text() ); });
you can bind buttons on page delegate:
$("body").on("click", ".btn", function(event){ alert($(this).text()); });
Comments
Post a Comment