title: calling a function before onclick script
body: <pre><code>&lt;a href="#" onclick="foo()"&gt;click me &lt;/a&gt;
  </code></pre>
  
  <p>Hello, I need to called a function before calling the onclick script when the  is clicked.</p>
  
  <p>I tried:</p>
  
  <pre><code>    var script = $("a").attr("onclick");
      $("a").attr("onclick", "");
  
      $("a").click(function(event) {
         // call bar() first, then foo();
         bar();
         // script is a string on Chrome
         // foo() may use this, so can not globalEval.
      });
  </code></pre>
  
  <p>how to call the script? Can I get the onclick as jQuery function? so that:</p>
  
  <pre><code> onclickFunction.call(this);
  </code></pre>
  
  <p>Thanks.</p>