contextmenu icon indicating copy to clipboard operation
contextmenu copied to clipboard

Dynamically change menu items

Open yig opened this issue 11 years ago • 1 comments

Is it possible to dynamically change menu items, or even just the text labels?

yig avatar Dec 31 '13 01:12 yig

Yes, by modifying the DOM nodes:


// Boolean we will toggle as an example:
var hidden = false;

var menu = contextmenu([{
    label: "Hide",
    onclick: function (e) {
        hidden = ! hidden;
        var labelText = hidden ? 'Show': 'Hide';
        // e.srcElement refers to the <menuitem> node.
        e.srcElement.setAttribute('label', labelText);
    }
}]);

contextmenu.attach(document.body, menu);

aantthony avatar Dec 31 '13 01:12 aantthony