title: Get id of a span inside a td of a dynamic table, on click
body: <p>I'm trying to get the id of a span created dynamically in a table. I created the table like this :</p>
  
  <pre><code>var initTable = function () {
  $.getJSON(jsonFile, function (data) {
      var items = [];
      $.each(data, function (key, val) {
          var spanid = val.key;
          items.push(
              '&lt;tr&gt;&lt;td&gt;' + val.label + '&lt;/td&gt;'
              + '&lt;td&gt;&lt;span class="parameters" id="' + spanid + '"&gt;---&lt;/span&gt; ' + val.value + '&lt;/td&gt;&lt;/tr&gt;'
              );
          });
          $("#myTable tbody").html(items.join(""));
      });
  };
  </code></pre>
  
  <p>When I click on the td, I need to get the id of the span. My query is like this :</p>
  
  <pre><code>$("#myTable span").click(function () {
  
      var id = $(this).attr("id");
      alert(a);
  });
  </code></pre>
  
  <p>It doesn't work. Someone has an idea why?</p>
  
  <p>Thank you</p>