How can I trigger an event on an element in Polymer?
The correct way to trigger a click event is calling click()
instead of onclick()
, so the correct function would be
doClick: function(event, detail, sender) {
console.log('Keypress event triggered');
sender.click();
}
here is the JSFiddle Demo
You can also call the function instead of triggering an event if you are pointing the same element
Polymer('my-element', {
clickEvent: function() {
console.log('Click event triggered');
},
doClick: function(event, detail, sender) {
console.log('Keypress event triggered');
this.clickEvent();
}
});
here is another JSFiddle Demo