Reputation: 1635
I am following discovermeteor.com tutorials, trying to do be creative and add my own stuff to it. One thing I want to do is to use jQuery to set a session value to be used as page title (not sure if that makes 100% sense though).
So I have been trying to trigger a session.set on document ready when some condition is met, but it doesn't seem to work.
my code example:
Template.layout.helpers({
pageTitle: function() { return Session.get('pageTitle'); }
})
jQuery(document).ready(function($) {
if ( $('section#main').hasClass('postlist')) {
Session.set('pageTitle', 'Posts list');
};
});
So, my question is, how do I work with jQuery and Meteor? Can I use jQuery just the way I am used to, or is there anything special I should be aware of? Many thanks
Upvotes: 2
Views: 6688
Reputation: 25882
In Meteor we don't use $(document).ready, instead you should use Meteor.startup which is equivalent :
Meteor.startup(function() {
if ( $('section#main').hasClass('postlist')) {
Session.set('pageTitle', 'Posts list');
};
});
Upvotes: 3