title: Passing function while running a loop
body: <p>I am starting off with html5 and not sure if I'm doing anything wrong in here.</p>
  
  <p>What I'm trying to achieve is create a portfolio of items and when one is selected, pass the selected item to a function to process it.</p>
  
  <p>I have put up a simple jsfiddle in here <a href="https://jsfiddle.net/rohannayak90/9u9rtf84/" rel="nofollow">https://jsfiddle.net/rohannayak90/9u9rtf84/</a></p>
  
  <pre><code>data = JSON.parse('{"error":false,"items":[{"id":1,"name":"John"},{"id":2,"name":"Jordan"}]}');
  
  jQuery.each(data.items, function(counter, item) {
    //console.log(item);
    h = '&lt;a href="#" onclick="' + generateCallBack(item) + ';"&gt;' + item.name + '&lt;/a&gt;&lt;/br&gt;';
    $('#portfolio').append(h);
  });
  
  function generateCallBack(argItem) {
      return function() {
        itemSelected(argItem);
      };
  };
  
  function itemSelected(argItem) {
    //console.log(argItem.name);
    alert(argItem.name);
  };
  </code></pre>
  
  <p>Thanks in advance.</p>