title: Why do I need setTimeout in this code
body: <pre><code>$(document).on('click', '#JS_btn1', function(e) {
    var self = $(this);
    setTimeout(function(){
      self.parent('div').html('&lt;a href="javascript:void(0);" class="btn_ok" id="JS_btn2"&gt;OK&lt;/a&gt;');
    });
  })
  </code></pre>
  
  <p>The code shows that #JS_btn1 was replaced by #JS_btn2 before finishing the listener events. Now the question is that why does I need setTimeout in IE7/8 to prevent error?</p>