title: attach event to dynamic element
body: <p>Hey im having a problem attaching an event to an element im dynamically generating. I would appreciate any advice on solving the issue im not sure whether its the method that im using to attach the event or whether its something else:</p>
  
  <pre><code>for (var i = 0; i &lt; array.length; i++) { 
  itemlist=itemlist.concat('&lt;pre'+' id="pres'+i+'"'+'&gt;'+array[i]+'&lt;/pre&gt;');
  
  var name = '#pres'+i;
  $( name ).click(function() {
    alert( "Handler for .click() called." );
  });
  }
  </code></pre>
  
  <p>I also tried this method which i found on stack overflow however yielded no result :</p>
  
  <pre><code>var name = '#pres'+i;
  $(name).on('click', function() {
      alert( "Handler for .click() called." );
  });
  </code></pre>
  
  <p>Whilst inspecting in chrome all of the elements exist with the correct ID, however the jquery event i have attached does not perform its alert. I have looked at some solutions however i do not want to attach the same function to all "" tags however attaching the same event to each of the ones in the loop would be acceptable.
  Any help would be appreciated :)</p>