» Forums
» DynarchMenu forum
» Support
» Assign a context menu to a dynamically created HTML element
» Re: Assign a context menu to a dynamically created HTML element
» Re[2]: Assign a context menu to a dynamically created HTML eleme
| Re[2]: Assign a context menu to a dynamically created HTML eleme ¶ | |
| Thanks a lot for your prompt reply. Actually I thought on the solution you suggested, but I really don't like to call the "setup" method each time a new element is created, especially when there are a lot of HTML elements in the document that need to be parsed (I imagine a large tree, dynamic, with 2000-3000 nodes, each node having a context menu assigned). I'm thinking on another solution: creating a single element in the document, hidden, standard assigning the context menu using "setup" and, for all dynamic created elements of that type, treat "oncontextmenu" and "onclick" handlers through the similar handlers in the hidden element: | |
| Re[3]: Assign a context menu to a dynamically created HTML eleme ¶ | |
| You could try the idea but I'm not sure you will be able to determine the element that was actually clicked on in your handler. | |
| last |
| Re[4]: Assign a context menu to a dynamically created HTML eleme ¶ | |
| I tried something like that: where: triggerCtxMenu = function(e, nodeInfo) { and the hidden element having the ID "options" is a DIV, "nodeInfo" is the information related to the element that triggered the menu (node.name): (Note: "getElById" is an utility function for "document.getElementById") The handler has the following implementation: I haven't tried yet to pass the object reference to the hidden element (as an attribute)... | |
| last |
(*) Discounts available for the above products!













