I am trying to create the same event handler for multiple elements, but cannot find anywhere in the documentation to do this. In the below example, I am trying to create a click handler for all text handings. This works for h1
, but not for the rest.
Template.page.events({ 'click h1, h2, h3, h4, h5, h6' : function (e, template) { console.log("clicked"); } }
The addEventListener() method You can add many event handlers of the same type to one element, i.e two "click" events. You can add event listeners to any DOM object not only HTML elements. i.e the window object. The addEventListener() method makes it easier to control how the event reacts to bubbling.
One event can have more than one event handler method in the same class or in different classes. At the run time only one handler method will be triggered at a time. After triggering the one that has to be deactivated and then another handler method will have to be registered to be triggered.
JavaScript Event HandlersEvent handlers can be used to handle and verify user input, user actions, and browser actions: Things that should be done every time a page loads. Things that should be done when the page is closed. Action that should be performed when a user clicks a button.
The event handler can trigger an object method or any general activity when the event occurs. JavaScript applications are largely event-driven. Other event examples are: click - clicking a button is an event; change - changing a text field; and select - selecting text from a text field.
Try this:
Template.page.events({ 'click h1, click h2, click h3, click h4, click h5, click h6' : function (e, template) { console.log("clicked"); } }
I believe event maps do not support comma separated selectors because commas are used to delimit individual event names or event selector
pairs.
http://docs.meteor.com/#eventmaps
Template.page.events({ 'click h1, click h2, click h3, click h4, click h5, click h6' : function (e, template) { console.log("clicked"); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With