jquery: Add code to click event
<p>I want to keep a reference of the button click function, do my stuff, then run the original click function.</p>

<p>I know usually I can do such things in document.ready, e.g:</p>

<pre><code>    var originalOnClick = $("#myBtn").click;
    $("#myBtn").click = function() {
      // do my staff here, and only then call the original:
      originalOnClick();
    }
</code></pre>

<p>(please correct this code if it is wrong!)</p>

<p>but, I have a special case. in my page onLoad function, there are asynchronous ajax calls. so functions called on document.ready are actually called before the ajax code was finished.</p>

<p>Is there a way to change the click event when calling click() or onclick() ? I mean, is there an event that is called immediatly before\after the click event?</p>

<p>or that I must ask the user to click a (I can see that this page is loaded) button, and only then I can do my staff ?</p>

<p>EDIT 1: The ajax code is in an included script. I cannot change it. </p>

<p>EDIT 2: Possible solution: hide the original button, but use its event:</p>

<p>HTML:</p>

<pre><code> &lt;div class="object1" style="display: none;" &gt;original button.&lt;/div&gt;
 &lt;div class="object2"&gt;my button.&lt;/div&gt;
</code></pre>

<p>JS:</p>

<pre><code>function doMyStuff() {
    alert(' doMyStuff .');
}

$(document).ready(function(){

  $('.object1').click(function(){
     alert('original staff. ');        
  });  // actually, this is just a test code. In my project, I cannot edit this function

  $('.object2').click(function() {
   doMyStuff();
    $('.object1').click();      
  });
});
</code></pre>
