javascript - Meteor doesn't run jQuery -


i have jquery code

if (meteor.isclient){  jquery(document).ready(function(){      jquery('#content .row > div').mouseenter( function(){         jquery('#content .row div .edit').toggle();     });      jquery('#content .row > div').mouseleave( function(){         jquery('#content .row div .edit').toggle();     }); });  } 

when run app doesn't work. if put chrome console works perfectly. what's problem?

this happened before different code.

your code adds callbacks dom elements exist when code executed. however, meteor add stuff page later, when rendering templates. here's how should done:

option 1) use meteor events

template.asdf.events({     'click .classname': function(e) {         ...     } }); 

option 2) in rare cases need not work in previous way, put jquery stuff in rendered callback:

template.asdf.rendered = function(){     _.each(this.findall('.classname'), function(element){          $(element).on('mouseenter', function(){...});     }); }; 

option 3) in ultra-rare cases when need special treatment page, use jquery live binding

meteor.startup(function(){     $('#content .row > div').on('click', function(){...}); }); 

Comments