title: Open Link in New Tab on Button Active
body: <p>I'm trying to have a button on my website that when is active(on click once) adds target <code>_blank</code> to a <code>href</code> links that has a certain class so they open in a new tab.</p>
  
  <p>This is the code for the button</p>
  
  <pre><code>    &lt;li id="toolbar-display"&gt;
          &lt;dl&gt;
          &lt;dt&gt;Display&lt;/dt&gt;
          &lt;dd id="toolbar-display-newtab" class="first last"&gt;&lt;span&gt;New Tab&lt;/span&gt;&lt;/dd&gt;
          &lt;/dl&gt;
      &lt;/li&gt;
  </code></pre>
  
  <p>Then this is a href link class that I would like to add <code>_blank</code> to.</p>
  
  <pre><code>    &lt;a class="item-link" href="url"&gt;
  </code></pre>
  
  <p>So for this, I use the following javascript which I modified from <a href="http://jsfiddle.net/UJMgQ/2/" rel="nofollow">http://jsfiddle.net/UJMgQ/2/</a> </p>
  
  <pre><code>    &lt;script type="text/javascript"&gt;
          $(function () {
          $('#toolbar-display-newtab').click(function () {
          if ($(this).toggleClass('active')) {
          $('.item-link').attr('target', '_blank');
          } else {
          $('.item-link').removeAttr('target');
          }
          });
          });
      &lt;/script&gt;
  </code></pre>
  
  <p>The code looks like it's correct, but unfortunately it doesn't work and I'm unclear at this point whether it's not detecting the button's active state or its not able to add <code>_blank</code>. Any help would be appreciated =)</p>