title: Combine Two identical jQuery functions except they use different selectors and classes
body: <p>I have two functions that do the same thing, except the element I am targeting is different and so is the ID I want to add. What is the best way to combine these into a single function?</p>
  <pre><code>  &lt;script&gt;
        $('.Index-page--has-image[id*=&quot;angle-right&quot;]').each(function(){
          var index = $(this).index('.Index-page--has-image')
          $('.Parallax-host .Parallax-item').eq(index).attr('id','angle-right');
        });
          $('.Index-page--has-image[id*=&quot;angle-left&quot;]').each(function(){
          var index = $(this).index('.Index-page--has-image')
          $('.Parallax-host .Parallax-item').eq(index).attr('id','angle-left');
        });
      &lt;/script&gt;
  </code></pre>