(JQuery) How to call a custom function before following link
- by morpheous
I want to achieve the following behavior in a page link.
When the link is clicked, I want to:
First, send (POST) some data back to the server
Second, allow the browser to navigate to the url that the link was pointing to.
I am relatively new to JQuery, and here is my first attempt below. I will be grateful to any jQuery gurus in here to fillin the blanks (and maybe point out how the snippet below may be improved).
<html>
<head>test page</head>
<body>
<div><a id="hotlink" href="http://www.example.com">Clik and see</a></div>
</body>
<script type="text/javascript">
$(document).ready(function(){
$('hotlink').click(function(){
//AJAX Post data here ...
//follow the link url (i.e. navigate/browse to the link) ...
});
});
</script>
</html>