Reputation: 605
looking at this event (being bind on 2 divs overlapping each other, look at the jsfiddle)
.on('contextmenu', function() { ... });
DEMO: jsfiddle
Thanks for any information!
Upvotes: 2
Views: 4429
Reputation: 1891
You need to prevent event from propogating, try this code:
$('#div1').on('contextmenu', function(e) {
if(!e.isDefaultPrevented()){
$('#log').append('<p>div1 triggered contextmenu!</p>');
e.preventDefault();
}
});
$('#div2').on('contextmenu', function(e) {
if(!e.isDefaultPrevented()){
$('#log').append('<p>div2 triggered contextmenu!</p>');
e.preventDefault();
}
});
Upvotes: 1
Reputation: 57095
$('#div1,#div2').on('contextmenu', function (e) {
e.stopPropagation();
$('#log').append('<p>' + e.target.id + ' triggered contextmenu!</p>');
});
Upvotes: 1