berg berg - 1 year ago 79
Javascript Question

HTML5 contextmenu - Access originally clicked element when menu item is clicked

I'm experimenting with the HTML5 contextmenu item in the latest version of Firefox (only browser that currently supports it). When I click on a menu item from the context menu how can I access the original element that was clicked when the menu was spawned?

The use case would be displaying a list of items and you want the user to perform an action on a particular item. Once the action is clicked from the menu you need a way to determine what element in the list was originally clicked on to spawn the menu.

Here is a JSFiddle (use Firefox to test)

Answer Source

Just save it somewhere like this.cte = arguments[0]; then retrieve it later document.getElementById('testitem').cte

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