swisnl / jQuery-contextMenu

jQuery contextMenu plugin & polyfill
https://swisnl.github.io/jQuery-contextMenu/
MIT License
2.25k stars 744 forks source link

Left click picking up parent as well as targeted child div #766

Closed CraigSheppardSec closed 1 year ago

CraigSheppardSec commented 1 year ago

Firstly thanks for this, really enjoying it.

I'm having an issue where if I set the trigger to 'right', everything works as it should; it correctly identifies the div that I've right clicked on and I can do what I need to do with that.

However if the trigger is set to 'left' it registers the click on not only the targeted child div but the underlying parent div as well. It throws an error that there's no menu for the parent div, however in some circumstances there is in which case it shows both the menu set for the child and parent.

Any ideas?

CraigSheppardSec commented 1 year ago

For anyone having a similar problem, it's a simple matter of adding a stopPropagation.

I have 2 different calls, one if the class is the parent div and one if the class is a child div.

Under the one for the child div...

trigger: 'left', selector: ".[child div class name]", build: function($trigger, e) { e.stopPropagation();

Problem solved.