title: MeteorJS check if template instance has a DOM
body: <p>I'm trying to do some DOM manipulation on every evaluation of a helper function, <code>{{htmlMarkup}}</code>. The problem is that when the page loads the helper is triggered before the template has a DOM.</p>
  
  <pre><code>Template.myTemplate.helpers({
      htmlMarkup:function(){
          var tmpl = Template.instance();
          tmpl.$('.code-container').empty();
  
          Tracker.afterFlush(function(){
              Prism.highlightElement(tmpl.$('.code-container')[0]);
          });
          return input.get();
      }
  });
  </code></pre>
  
  <p>I will get the error message <code>Exception in template helper: Error: Can't use $ on template instance with no DOM</code>. I have tried to check if <code>tmpl.firstNode</code> is undefined but it doesn't work. What is the best way to solve this?</p>