I have this anchor and on click I would like to popup something. This href is within a page that has other hrefs.
<a class="sign_new" href="#sign_up">Sign up</a>
jQuery:
$(document).ready(function(){
$('a[href = "sign_up"]').click(function(){
alert('Sign new href executed.');
});
});
The above code does not fire up.
If you just need to trigger a click event, you can omit the line that begins with for( . @Parag: Read it again. The loop is to click the same link 50 times, which is what it does.
Answer: Use the jQuery click() Method You can use the click() method to trigger a click on a link programmatically using jQuery.
If you want native JS to trigger click event without clicking then use the element id and click() method of JavaScript.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With