title: Accessing DOM element in async AJAX callback returns undefined
body: <p>I run a function named <code>hookUser</code> to query a DB every 2 seconds to check if a user is online, but it raises this error:<br></p>
  
  <blockquote>
    <p><code>cannot read innerHTML of undefined</code></p>
  </blockquote>
  
  <p>I suspect it's because the async callback is not in same scope?</p>
  
  <p>The issue is that I can't pass the button object into that callback, can I do it? If not, is there another way to make this work?</p>
  
  <p>Any help is appreciated.</p>
  
  <pre><code>            &lt;script&gt;
                  function hookUser(user)
                  {
                      console.log('HOOKED USER: '+user);
                       setInterval(
                           function(user)
                           {
                              var ajaxurl = 'checkonline.php',
                              data =  {'username':user};
                              $.post(ajaxurl, data, function (response) {
                                  var button = document.getElementById('button_'+user);
                                  if(response){
                                      console.log(user+'ONLINE');
                                      //button.innerHTML = 'ONLINE';
                                      //button.className = 'btn btn-xs btn-success';
                                  }else{
                                      console.log(user+'ONLINE');
                                      //button.innerHTML = 'OFFLINE';
                                      //button.className = 'btn btn-xs btn-danger';
                                  }
                              });
                           },2000);
                  }
                  &lt;/script&gt;
  ...
  &lt;div class="col-md-3"&gt;
                              &lt;div class="col-md-12 thumb-user " &gt;
                              &lt;div&gt;
                              &lt;button id='button_&lt;?php echo $current_user;?&gt;' class='btn btn-xs btn-success' &gt;Unknown&lt;/button&gt;
                              &lt;?php echo '&lt;script&gt;hookUser(\''.$current_user.'\');&lt;/script&gt;';?&gt;
  ...
  </code></pre>