Template.body.events


#1

i put this in my html

<div class=“testclass”>
testclass click
</div>

and this in the js.

Template.templatename.events({

"click .testclass": function (event) {
  alert("hello");

}

});

–> it works fine.

but i am using this class in many templates, so i figured i use template.body.events instead (like in the tutorial with a form):


Template.body.events({

"click .testclass": function (event) {
  alert("hello");

}

});

–> nothing happens.
so template.body.events is not a way to globally ‘listen’ to events?
how is it then possible to create a class and assign it a behaviour throughout many templates?
otherwise i would have to write the same code for multiple templates.

thanks in advance.


#2

The answer there is meteor add gwendall:body-events. Always works for me.


#3

cool, now it works. many thanks!!!

template.body is used in the tutorial with a form, there is no hint to it being restricted to forms or whathaveyou.