contextMenu.js
contextMenu.js copied to clipboard
How to tell what menu item was clicked in generic click function
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.
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>