Paul Paul - 6 months ago 52
jQuery Question

How do I close a jquery contextMenu?

I'm using a jquery contextMenu plug-in and have a small issue I'm trying to resolve.

Currently when I click my 'delete' menu item the function I call prompts the user with a confirmation box from the deleteTests function. At this point the contextMenu is still visible and the confirmation box.

Ideally I would like to close the contextMenu as soon as the user selects a menu item and then proceed to the delete function.

This seems like it should be trivial but I can't seem to get it working.

$.contextMenu({selector: '#context-menu', items: {
"delete": {name: "Delete", icon: "delete", callback: menu_click },
sep1: "---------",
quit: {name: "Quit", icon: "quit", callback: $.noop}

function menu_click(key, opt) {
if (key == "delete") {
// Need to close menu here


You're right. It should be trivial, but the author did not provide this functionality.

You can look at the source and copy whatever the author did when clicks outside of the menu are detected, but this is a hack.

You're in luck; I've done the same thing with this plug-in myself.

The following will do, but remember that it's a hack: