Skip to content Skip to sidebar Skip to footer

Jquery On Click Event Firing Multiple Times

I just learned how to use the method .on() and I use it to add an event handler to some buttons that are added 'live' (after the DOM is ready). $('#table').on('click', '.delete',

Solution 1:

just add off() before on() to remove existing event on it

there's a possibility that you already bind an event in that element so if you want to rebind the event you just off('event') to avoid firing event multiple times

$('#table').off("click").on("click", ".delete", function() {
    var data_name = $("#dataSelector option:selected").attr('name');
    alert(data_name);
});

Solution 2:

I tested your code, for me its working fine. may be in code you give same id for selector and delete button. please check and give unique name to each of your objects.

Post a Comment for "Jquery On Click Event Firing Multiple Times"