The javascript
is used for different actions in an HTML document. The href
is an attribute to specify hyperlink reference with the <a>
tag. The href attribute can be used with Javascript code like javascript:void(0)
. In this tutorial, we examine what the “href=javascript:void(0)”.
href=javascript:void(0)
Let’s start investigating the meaning of the “href=javascript:void(0)” by separating every attribute or code.
The href
is an attribute of the <a>
. The href is used to specify a link or action when the link is clicked. Generally, URLs are used to specify a link. But like this example, a JavaScript code can be also used to trigger when clicked to the <a> tag.
The javascript:
is used to specify we will define a JavaScript code or function rather than a link.
void(0)
is a popular JavaScript statement that is used to do nothing. Yes, this statement does not do anything. The void() is used to express emptiness or nothing and the parameter 0 also does nothing.
Why Use “href=javascript:void(0)”?
You may ask if it does nothing why should use the “href=javascript:void(0)”. Links are generally used to redirect new pages or web site which is common usage. If we do not want to open a new page or website we can use this statement which is very clear to read.
Alternatively we want to use Javascript to redirect new page or site in the future but current we do not implemented this we can use this code to fill the href attribute and implement in the feature easily.