jQuery click event not working, works in console

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?

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.

2 Likes

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

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

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

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.

1 Like