Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to close JQuery context menu in HTML/js code

Status
Not open for further replies.

Diego Donate

Programmer
Jul 30, 2018
3
ES
Hi,
I have an application with some HTML/js code. I am using jquery to show a contextmenu ( in the $document element when I rightclick in a div of this document. With 'autohide' it closes when mouse leaves the HTML document, but I would like to close the context menu in some other situations, but I don't know how to close the menu programatically.

My code:

$(document).contextMenu({ selector: '#' + panelId, autoHide: true, items: ... callback: function(key, options) { if (key === ... }

I have a function where I need to close the menu, but all my tests fail:

function() { $(document).contextmenu(false); $(document).trigger('contextmenu:hide'); $trigger = $('#' + panelId); $trigger.contextMenu(false); } 'panelId' is a value I get when I rightclick in the div, using 'oncontextmenu' attribute with 'myFunction' value. So 'myFunction' is called before displaying the context menu, and I save there the id, to be used to enable/disable items when the menu is 'about to show'

I hope someone could help me about how to close the menu,

Thanks in advance,
Diego
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top