May 8, 2018

JQuery how to prevent event handling (clicking etc.) more than once

You created  some delegated event handler for DOM event:

$( "#dataTable tbody tr" ).on( "click", function() {


Problem is that when you click on control Click event occurs more than once.
Check your code. Probably inside page life on client side you perform above event click registration multiple times. Thus every click triggers Click events based on how much registrations has happened.

To avoid this use Off method.
Place it right before On tho cleary any previous event registration on SAME function like this:

 $( "body" )
    .off( "click", "#theone", flash )

$( "body" )
    .on( "click", "#theone", flash )


http://api.jquery.com/off/

No comments:

Post a Comment