How to call javascript from a href?
like:
<a href="<script type='text/javascript'>script code</script>/">Call JavaScript</a>
In JavaScript, you can call a function or snippet of JavaScript code through the HREF tag of a link. This can be useful because it means that the given JavaScript code is going to automatically run for someone clicking on the link. HREF refers to the “HREF” attribute within an A LINK tag (hyperlink in HTML).
The href attribute specifies the URL of the page the link goes to. If the href attribute is not present, the <a> tag will not be a hyperlink. Tip: You can use href="#top" or href="#" to link to the top of the current page!
<a onClick="yourFunction(); return false;" href="fallback.html">One Way</a>
** Edit **
From the flurry of comments, I'm sharing the resources given/found.
Previous SO Q and A's:
Interesting reads:
<a href="javascript:call_func();">...</a>
where the function then has to return false so that the browser doesn't go to another page.
But I'd recommend to use jQuery (with $(...).click(function () {}))
)
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