title: onclick funtion when I add a button in ajax
body: <p>I want to use AJAX to get information. If succeeds, I want to append the data into a table. Also, in each <code>tr</code>, I add a button, and I want to trigger an event if I click the button. Thus, I just append a button with an <code>onclick</code> function into the table. While, the <code>onclick</code> function does not work. Does anyone know why? and how I can reach my goal? </p>
  
  <p>Here is the code:</p>
  
  <pre><code> $.ajax({
      url: 'https://api.instagram.com/v1/tags/'+tag+'/media/recent',
      type: "GET",
      dataType: "jsonp",
      cache: false,
      data:{
          access_token: access_token,
          count: count
      },
      success: function(data){
         for(var x in data.data){
           var html="";
           tdHtml +="&lt;tr&gt;&lt;td&gt;"+"&lt;a href='"+data.data[x].link+"'&gt;&lt;img src='"+data.data[x].images.thumbnail.url+"'&gt;&lt;/img&gt;&lt;/a&gt;"+"&lt;/td&gt;"+ 
                      "&lt;td class='text-center'&gt;"+data.data[x].caption.from.username+"&lt;/td&gt;"+
                      "&lt;td class='text-center'&gt;"+data.data[x].likes.count+"&lt;/td&gt;"+
                      "&lt;td&gt;"+create_time+"&lt;/td&gt;"+
                      "&lt;td&gt;"+tags+"&lt;/td&gt;"+
                      "&lt;td&gt;"+"&lt;button id='addUsers' class='btn btn-primary btn-xs' onclick='addUsers()'&gt;Add Users to a Group&lt;/button&gt;"+"&lt;/td&gt;&lt;/tr&gt;";
       }
    }
  });
  </code></pre>
  
  <p><strong>EDIT:</strong>
  Actually, the <code>onclick</code> function is like this:</p>
  
  <pre><code> "&lt;td&gt;"+"&lt;button id='addUsers' class='btn btn-primary btn-xs' onclick='addUsers('"+data.data[x].caption.from.username+"')'&gt;Add Users to a Group&lt;/button&gt;"+"&lt;/td&gt;&lt;/tr&gt;";)'&gt;Add Users to a Group&lt;/button&gt;"+"&lt;/td&gt;&lt;/tr&gt;";
  </code></pre>
  
  <p>Once I click the button, I can do something with the data's username I get via AJAX. However, even if I write simply, it cannot work. For example:</p>
  
  <pre><code>function addUsers(name){
    console.log(name);
  }
  </code></pre>
  
  <p>The name cannot be consoled. There is an undefined error, or other error happened. </p>
  
  <p>So, the goal for me is to get response from developer(done), append it to a table in html(done), and click a button(which was append formerly) to do more things with the appended information. Here, I want to add the name into a certain list. </p>