attach a context menu to all items matching selector?
Hi Max, unfortunately this is not supported at the moment, you would need to loop over all elements and attach the event handler yourself, using the show method in the callback.
I'm currently working on a bigger update, so I can include it as a requested feature, I think it may be useful for many usecases.
Simply like this?
const elements = document.querySelectorAll('.myclass');
elements.forEach(function(element, index) {
ctxmenu.update(element.id, menuDefinition);
});
yes, that's the simplest way =)
Simply like this?
const elements = document.querySelectorAll('.myclass'); elements.forEach(function(element, index) { ctxmenu.update(element.id, menuDefinition); });
By the way @smalos, are you using the attach method at all? 😅
I just use the update method, because
"If you try to update a menu which does not exist, it will silently be attached instead."