title: Add More Attachments and Stop at a Certain Number
body: <p>I create a button to add more attachments.  It works well and I want to stop at a certain number, for example at 5 attachments, they cannot attach anymore.  I set <code>i &lt;6;</code>, but it doesn't stop at 5 attachments.  Live Code <a href="http://jsfiddle.net/abcid/e1c3xu01/" rel="nofollow">http://jsfiddle.net/abcid/e1c3xu01/</a></p>
  
  <p>HTML</p>
  
  <pre><code>&lt;div class="attachFile"&gt;&lt;input type="file" /&gt;&lt;/div&gt;&lt;button id="addNew"&gt;Add&lt;/button&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;div class="attachField"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>JS</p>
  
  <pre><code>$(document).ready(
      function()
          {
              var i=0;
              $('#addNew').click(
                  function()
                      {
                          i++; i &lt;6;
                          $('.attachField').append( '&lt;div class="attachFile"&gt;&lt;input type="file" /&gt;&lt;/div&gt;' );
  
  
              }); //end click
  
          }); //end ready
  </code></pre>
  
  <ol start="2">
  <li>Different way, I like to disappear the Add button after 5 attachments, but my syntax below doesn't work out.  Live code <a href="http://jsfiddle.net/abcid/f2wc6srm/2/" rel="nofollow">http://jsfiddle.net/abcid/f2wc6srm/</a></li>
  </ol>
  
  <p>JS</p>
  
  <pre><code>$(document).ready(
      function()
          {
              var i=0;
              $('#addNew').click(
                  function()
                      {
                          i++;
                          $('.attachField').append( '&lt;div class="attachFile"&gt;&lt;input type="file" /&gt;&lt;/div&gt;' );
  
              if( i = 5)
              {
              $('#addNew').hide;
              }
              }); //end click
  
          }
  ); //end ready
  </code></pre>