Append an onClick event to an anchor tag using jquery?

Posted by M.Woodard on Stack Overflow See other posts from Stack Overflow or by M.Woodard
Published on 2010-06-16T22:50:13Z Indexed on 2010/06/16 22:52 UTC
Read the original article Hit count: 114

Filed under:
|

I am trying to add an onClick event to an anchor tag ...

Previously i had ...

<a href="somlink.html" onClick="pageTracker._link(this.href); return false;">

But i am trying to avoid the inline onClick event because it interferes with another script..

So using jQuery i am trying the following code ...

<script> $(document).ready(function() { $('a#tracked').attr('onClick').click(function() {window.onbeforeunload = null; pageTracker._link(this.href); return false; }); }); </script>

with the html like so <a id="tracked" href="something.html">

So my question is should this be working, and if not what would be the best solution?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery