CtxMenu-Javascript icon indicating copy to clipboard operation
CtxMenu-Javascript copied to clipboard

How to get the clicked element

Open TheWilley opened this issue 1 year ago • 1 comments

Please correct me if I'm wrong, but the documentation mentions no way get the element that was clicked on. There is, however, a way to get it.


contextMenu.addItem("alertElement", function () {
    alert(contextMenu._elementClicked)
});

I assume the _elementClicked variable is not supposed to be accessed, as it's marked as private. Still, I thought it could be worth mentioning!

TheWilley avatar Aug 17 '22 18:08 TheWilley

Hi,

The first argument passed into the function will be the clicked element:

contextMenu.addItem("alertElement", function (clickedElement) {
    alert(clickedElement)
});

You can see an example of this with the ChangeElementColor function in the example page source.

But yes, I should definitely mention that somewhere in the documentation, thanks for letting me know!

nils-soderman avatar Aug 18 '22 11:08 nils-soderman