Delegate event firing twice
This delegate event is firing 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"'s.
Any thoughts on how to stop it? I tried event.stopPropagation(), and also undelegating and re-dele开发者_Go百科gating to no avail.
This is in Chrome, as part of a Chrome plugin.
Depending on how you register the delegate, you might want to do:
$("#client-plugin").undelegate('event').delegate('event', ...)
Also, try to add a return false
from your handler.
You need to stop immediate propagation
$("#client-plugin").on(".client-button", "click", function (e) {
e.stopImmediatePropagation();
var id = this.id.split('-')[2];
client.retrieveMessageByID(id);
});
精彩评论