title: Get variable from loop
body: <p>I have a loop which is creating table:</p>
  
  <pre><code>for(m=1; m&lt;7; m++){
  
      document.getElementById('content').innerHTML += 
          ('&lt;tr&gt;' +
              '&lt;td&gt;' + m + '&lt;/td&gt;' + 
              '&lt;td&gt;&lt;input type="checkbox" id="switch'+m+'"&gt;&lt;label class="switch" for="switch'+m+'"&gt;Button ' + m + '&lt;/label&gt;&lt;/td&gt;' +
          '&lt;/tr&gt;')
  }
  </code></pre>
  
  <p>In every row in second TD is button which must be assigned to every row. Each button has his own row. I want to alert m from the first TD exactly when i click button from that row. I mean if i will click button is switch2 i will get alert from m "2".
  Here is the button code i tried:</p>
  
  <pre><code>var buttons = "#switch" + m
  
  $(function() {
      $(buttons).button();
      $(buttons).click(function(){                        
          alert(m);                                   
      });
  }); 
  </code></pre>
  
  <p>This is not working because all of the buttons alerting last value from loop = 6.
  I know it is confused but i hope you uderstand. Really appreciate your help </p>