Jquery href click - how can I fire up an event?
If you own the HTML code then it might be wise to assign an id to this href. Then your code would look like this:
<a id="sign_up" class="sign_new">Sign up</a>
And jQuery:
$(document).ready(function(){
$('#sign_up').click(function(){
alert('Sign new href executed.');
});
});
If you do not own the HTML then you'd need to change $('#sign_up') to $('a.sign_new'). You might also fire event.stopPropagation() if you have a href in anchor and do not want it handled (AFAIR return false might work as well).
$(document).ready(function(){
$('#sign_up').click(function(event){
alert('Sign new href executed.');
event.stopPropagation();
});
});
It doesn't because the href value is not sign_up
.It is #sign_up
. Try like below,
You need to add "#" to indicate the id of the href value.
$('a[href="#sign_up"]').click(function(){
alert('Sign new href executed.');
});
DEMO: http://jsfiddle.net/pnGbP/