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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -