I can't get delegation to work with events. I'm trying to have a certain function fire when a button within the element is pressed. However, when I use the syntax provided ('tap:delegate(button)': function(){});
) I get no response. Below is some example code, Some help would be appreciated.
HTML:
<my-tag></my-tag>
Js:
xtag.register('my-tag', {
content: '<span>Some Text</span><button>my button</button>',
events: {
'tap:delegate(button)': function(){
console.log('the button was pushed');
}
}
});
Your code is working for me. Something could be loading out of order. You could try wrapping your code with a
WebComponentsReady
event handler:I usually put the script tags at the bottom of the
<body>
to avoid this.Or if you're using something like webpack