title: Passing element to jQuery function
body: <p>I need to change the text of a html span element in a timer.
  The timer works well, but I have no sucess changing the span content.</p>
  
  <p>The problem is at:</p>
  
  <pre><code>$(element).text(hour);
  </code></pre>
  
  <p>What am I missing here?</p>
  
  <p>Here is my code:</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;span id="mytimer"&gt;00:00&lt;/span&gt;
  </code></pre>
  
  <p>Here is my JS:</p>
  
  <pre><code>function loaded(selector, callback){
          $(function () {
              callback($(selector));
          });
          $(document).on('DOMNodeInserted', selector, function () {
              callback($(this));
          });
     };
  
     function setupTimer(element, duration, interval) {
          var start = Date.now(),
              diff,
              minutes,
              seconds;
          clearInterval(window.mytimer);
          function timer() {
              diff = duration - (((Date.now() - start) / 1000) | 0);
              minutes = (diff / 60) | 0;
              seconds = (diff % 60) | 0;
              if (minutes &lt; 0) {
                minutes = 0;
              }
              if (seconds &lt; 0) {
                seconds = 0;
              }
              minutes = minutes &lt; 10 ? "0" + minutes : minutes;
              seconds = seconds &lt; 10 ? "0" + seconds : seconds;
              hour=minutes + ":" + seconds;
              $(element).text(hour);
              if (window.mytimer != null &amp; diff &lt; 0) {
                clearInterval(window.mytimer);
              }
          };
          timer();
          window.mytimer = setInterval(timer, interval * 1000);
      };
  
     loaded('#mytimer', function(el){
            setupTimer(el,100,1);
     });
  </code></pre>