Mcope
Mcope

Reputation: 781

Meteor - Template ONLY Events?

Is it possible to create a Meteor event for template only?

For example:

'click': function(){}

This will work anywhere on the browser, whether or not the clicked element was part of the template. What if I want to register an event for the template only? Is the only way to achieve this by doing 'click #DOM_ELEM_NAME' ?

Upvotes: 0

Views: 43

Answers (1)

Dan Dascalescu
Dan Dascalescu

Reputation: 152066

Events are captured only within the template that defines them:

Template.leaderboard.events({
  "click .button": function (event) {
    console.log('Only buttons in the leaderboard template trigger this');
  }
});

You shouldn't need to put ids in event selectors. Read more at Event maps.

Upvotes: 0

Related Questions