Jecker Jecker - 1 year ago 70
Javascript Question

Error when adding stopPropagation to contextMenu

I have downloaded the current version of JQuery-contextMenu plugin, and created a test page. In the test page if I use li elements the function propagates from the top li item down to the lower li items. Is there a method to stop this from happening? Thank you for your help.

<html>
<head>
<link href="dist/jquery.contextMenu.min.css" rel="stylesheet" type="text/css" />

<script language="javascript" src="https://code.jquery.com/jquery-3.2.1.js"></script>
<script language="javascript" src="src/jquery.ui.position.js"></script>
<script language="javascript" src="src/jquery.contextMenu.js"></script>
<script>
$(function(e) {
e.stopPropagation();
$.contextMenu({
selector: '.context-menu-one',
callback: function(key, options) {
var m = "clicked: " + key;
alert(m);
},
items: {
"edit": {name: "Edit", icon: "edit"},
"cut": {name: "Cut", icon: "cut"},
"copy": {name: "Copy", icon: "copy"},
"paste": {name: "Paste", icon: "paste"},
"delete": {name: "Delete", icon: "delete"},
"sep1": "---------",
"quit": {name: "Quit", icon: function(){
return 'context-menu-icon context-menu-icon-quit';
}}
}
});
});
</script>
</head>
<body>
<span class="context-menu-one btn btn-neutral">right click me</span><br>

<span class=" btn btn-neutral">right click me</span><br>
<ul >
<li class="Docs context-menu-one" style="list-style-type: none;"> Testing
<ul >
<li class="upTest" style="list-style-type: none;">
<a href="#">dfasfsdafas</a>
</li>
</ul>
</li>
</ul>
<span class=" btn btn-neutral">right click me</span><br>
<span class=" btn btn-neutral">right click me</span><br>

</body>
</html>

Answer Source

After further testing I found by adding an additional contextmenu and assigning none to the trigger, I received the results I wanted.

$(function(){ $.contextMenu({ selector: '.upTest', trigger: 'none', }); });

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download