What is the meanign of javascript:;
that is kept inside the href
attribute in an link?
Like
<a href="javascript: ... ;">Link</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).
Definition and Usage 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!
The anwer is: not possible.
This is a type of JavaScript link - the onclick attribute defines a JavaScript action when the 'onclick' event for the link is triggered (i.e. when a user clicks the link) - and there is a URL present itself in the onclick attribute.
IF you need to pass a javascript snippet which needs to run instead of the default behavior of an element then you use this javascript: ;
syntax.
For example
<a href="javascript:alert('');">Test</a> <!-- Runs on the click of the link -->
Similarly, you can combine these on other events also, like onclick
, onchange
etc but this is really not necessary, since you can execute the snippet, directly.
The uses of this, i have seen in years are:
<a href="javascript:void(0);">Test</a>
<form action="javascript:void(0);">..</form>
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