ctxmenu icon indicating copy to clipboard operation
ctxmenu copied to clipboard

attach a context menu to all items matching selector?

Open MaxBittker opened this issue 1 year ago • 5 comments

MaxBittker avatar Jun 06 '24 22:06 MaxBittker

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.

nkappler avatar Jun 06 '24 22:06 nkappler

Simply like this?

const elements = document.querySelectorAll('.myclass');
elements.forEach(function(element, index) {
    ctxmenu.update(element.id, menuDefinition);
});

smalos avatar Feb 06 '25 23:02 smalos

yes, that's the simplest way =)

nkappler avatar Feb 07 '25 08:02 nkappler

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? 😅

nkappler avatar Feb 07 '25 08:02 nkappler

I just use the update method, because

"If you try to update a menu which does not exist, it will silently be attached instead."

smalos avatar Feb 10 '25 07:02 smalos