jeudi 7 juillet 2016

Meteor won't run jQuery code

I'm trying to run a block of jQuery code that shows and hides a form, but can't find a way to get Meteor to run the code on the client side. Here's the code I'm attempting to use at the moment:

if (Meteor.isClient) {
    Template.post.onRendered(function(){
      $(document).ready(function(){
        $('.replybtn').click(function(){
          if( $(this).parent().next().css('display') === 'none' ){
            $(this).parent().next().css('display', 'block');
          } else {
            $(this).parent().next().css('display', 'none');
          }
        });
      });
    });
}

I've also tried putting the code in a script tag, which did not work. Strangely, the jQuery portion of the code alone works fine when pasted into the browser console - meaning the bug is likely in how I'm running the code in Meteor, not the jQuery itself. Also, I've confirmed that the template name is correct and can't think of any other issues that could be causing this. Any ideas on why the jQuery code may not be running?

Aucun commentaire:

Enregistrer un commentaire