contextMenu.js icon indicating copy to clipboard operation
contextMenu.js copied to clipboard

How to tell what menu item was clicked in generic click function

Open piller187 opened this issue 8 years ago • 1 comments

I'm loading the menu dynamically in a plugin system. I define 1 function for the fun property of each menu item. There doesn't seem to be a way for me to tell when inside this function what menu item was clicked.

piller187 avatar Nov 02 '16 17:11 piller187

The tag itself (and the text) is available in the 2nd argument to your function or the event. From that you can extract the text and determine the menu item:

arguments[1].target value: <li title="This is an example" class=iw-mSelected">Some Menu Item

or: event.target.innerText

If it's a submenu you can determine the parent item and figure out the context, should you have duplicate menu items.

Using JQuery: $(event.target).parent().parent()[0] result: <li title="New..." class="iw-has-submenu iw-mTrigger iw-mSelected>

leondanielking avatar Feb 24 '20 20:02 leondanielking