title: Get the id of elements dynamically created
body: <p>I want to select the elements created dynamically using ajax by id, the code is:</p>
  
  <pre><code>$(function(){
     $('#loadFeed').bind('click',function(){ 
          $.getJSON('getData.php', function(json) {
              var output="&lt;ul id='feedsList'&gt;";
  
              for(var i=json.posts.length-1;i&gt;=json.posts.length-31;i--){
                  output+="&lt;li class='post'&gt;";
                  output+="&lt;div class='text' id='"+json.posts[i].id+"'&gt;"+json.posts[i].shortmsg+"&lt;/div&gt;";         
                  output+="&lt;/li&gt;";
              }
              output+="&lt;/ul&gt;"
              $(output).appendTo('.posts');
      });
    });
  });
  </code></pre>
  
  <p>The html codes:</p>
  
  <pre><code>&lt;div class="posts"&gt;
      &lt;!--dynamic content here--&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I tried to get the id using $(this).attr("id"):</p>
  
  <pre><code>$(".post").on("click",".text",function(){
        var this_id =$(this).attr("id");
        alert(this_id);
  });
  </code></pre>
  
  <p>But it said undefined. How could I get the id correctly?Thanks!</p>