title: Adding onClick event to dynamically generated buttons?
body: <p>in Javascript .. If I have a dynamically generated buttons and I want a generic onClick function. How can I do that ?</p>
  
  <pre><code>&lt;script&gt;
  for(i=0;i&lt;something.length;i++){
     $('body').append('&lt;button id="btnInit'+i+'" &gt;'+i+'&lt;/button&gt;');
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I don't want to create a unique onClick function for each button. How can I do a single one that applies to all. e.g display its label text when pressed.</p>