Delegating an Event Twice

This delegate event is fired twice (not always, sometimes).

client.bindButtonClickFunction = function(){ $("#client-plugin").delegate(".client-button", "click", function() { var id = this.id.split('-')[2]; client.retrieveMessageByID(id); }); }; 

I call the function after inserting all the ".client-button".

Any thoughts on how to stop it? I tried event.stopPropagation (), as well as undelegating and re-delegating to no avail.

This is in Chrome, as part of the Chrome plugin.

+6
source share
2 answers

Depending on how you register the delegate you might want to do:

 $("#client-plugin").undelegate('event').delegate('event', ...) 

Also try adding return false from your handler.

+20
source

You need to stop the immediate spread

  $("#client-plugin").on(".client-button", "click", function (e) { e.stopImmediatePropagation(); var id = this.id.split('-')[2]; client.retrieveMessageByID(id); }); 
+7
source

Source: https://habr.com/ru/post/893913/


All Articles