Reputation: 3095
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");
}
}
Upvotes: 27
Views: 10908
Reputation: 6020
I solved a similar problem previously, which is reproduced below for handling multiple events on the entire document with a single handler:
Template.template_name_here.events({
'keyup, click': function(event) {
event.preventDefault();
console.log("KEYUP OR CLICK");
}
});
Upvotes: 1
Reputation: 8345
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");
}
}
Upvotes: 2
Reputation: 7680
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.
Upvotes: 53