title: How do I call a jQuery function on multiple elements without writing it twice?
body: <p>I want to use JS to add class <code>.block</code> to a tree of elements, up to a certain point—stopping when it reaches the first <code>div</code> element.</p>
  
  <p>If the user doesn't have JS enabled, the elements should not have the class; else, they should. That's why I'm using jQuery to add the class instead of writing it in the markup.</p>
  
  <p>Here's what I have:</p>
  
  <pre><code>&lt;div&gt;
    &lt;label&gt;
      &lt;input .../&gt;
      &lt;time&gt;
        &lt;span class="js-block"&gt;Wednesday, &lt;/span&gt;
        &lt;span class="js-block"&gt;Sep 28&lt;/span&gt;
      &lt;/time&gt;
    &lt;/label&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I want to add class <code>.block</code> to both <code>span</code>s, the <code>time</code>, and the <code>label</code>, (and not the <code>input</code>), and <strong>this works perfectly fine</strong>:</p>
  
  <pre><code>$('.js-block').addClass('block').parentsUntil('div').addClass('block')
  </code></pre>
  
  <p>Now the duplicate call <code>.addClass('block')</code> doesn't sit well with me, so I tried this, but it didn't work:</p>
  
  <pre><code>$('.js-block').add(function () {
    return $(this).parentsUntil('div')
  }).addClass('block')
  </code></pre>
  
  <p>Am I using <code>.add()</code> correctly?</p>
  
  <p>I have not tested whether this</p>
  
  <pre><code>$('.js-block').add($('.js-block').parentsUntil('div')).addClass('block')
  </code></pre>
  
  <p>works, because if it did work, it would be just as bad as calling the same function twice. The whole point is to not have repeated code.</p>