jQuery click event not working, works in console


#1

Hey all. So I’m trying to get a altered version of this codepen: http://codepen.io/teetteet/pen/Iwaqb working in Meteor. In the pen, it uses a simple jQuery statement to toggle a class on/off on a click event. It works fine in the pen, but in app the click event doesnt seem to trigger the toggle. If i manually go into the console and enter $('.cover').toggleClass('open'); all the panels flip down as they should. Any thoughts?

Is there a more “Meteor” way to go about triggering this event?

My first thought with Meteor would be to have a Template helper return the class, but im not sure how i would go about triggering that on a click event.

Ideas?


#2

I’m not sure as to how you currently have your code, but here is how I would do it.

Template.tweet.events({
   'click .cover': function(event, template){
     template.$('.cover').toggleClass('open');
   }
});

Hopefully this helps any.


#3

Nice, just what i was looking for. I’d rep ya if i could.


#4

The Meteor way is to create events(function) for handling these click, submit etc on a page like @jrudio has mentioned


#5

make sure your template is in client; not server. Share a bit more of your code context for more help.


#6

Have a read here
http://docs.meteor.com/#/full/template_events
and
http://docs.meteor.com/#/full/eventmaps

for more info.

the event hooks are pretty powerful and easy to implement.