$(".container").on("contextmenu", ".photos-bottom .albums li", function(e) {
$('html').bind('click', function (event) {
alert(id);
});
return false;
});
when I right click (for the contextmenu) multiple times and then left click html once, it triggers the alert the number of times that I right clicked.
So if I right click once, then left click, it shows a popup once. If I right click three times, then left click, it shows the popup three times.
Why is this so?
$(".container").on("contextmenu", ".photos-bottom .albums li", function(e) {
$('html').bind('click', function (event) {
alert(id);
});
return false;
});
when I right click (for the contextmenu) multiple times and then left click html once, it triggers the alert the number of times that I right clicked.
So if I right click once, then left click, it shows a popup once. If I right click three times, then left click, it shows the popup three times.
Why is this so?
Share Improve this question asked Jan 28, 2012 at 18:22 Dylan CrossDylan Cross 5,98623 gold badges79 silver badges120 bronze badges 3 |2 Answers
Reset to default 19$('html').unbind('click').bind('click')
fixed it.
Because your click event is being bound every time a context menu event occurs, you're actually adding an additional bind each time you right click. This is the reason for the ever-growing number of event executions.
You should either:
a) unbind the event when the context menu is closed, or
b) bind the click event outside of your contextmenu callback function.
click
event tohtml
? – gdoron Commented Jan 28, 2012 at 18:29click
handler in thecontextmenu
handler? This does not make a lot of sense. – Tomalak Commented Jan 28, 2012 at 18:29