You might have occasionally came across “javascript:void(0)” in an HTML Document. It is often used when inserting an expression in a web page might produce some unwanted effect. To remove this effect, “javascript:void(0)” is used. This expression returns undefined primitive value. This is often used with hyperlinks. Sometimes, you will decide to call some JavaScript from inside a link. Normally, when you click a link, the browser loads a brand new page or refreshes the same page (depending on the URL specified). But you most likely don’t desire this to happen if you have hooked up some JavaScript thereto link. To prevent the page from refreshing, you could use void(0).
Using “#” in anchor tag: When writing the following code in the editor, the web page is refreshed after the alert message is shown.
Example:
html
< h1 style = "color:green" >GeeksforGeeks</ h1 >
< h3 >without JavaScript:void(0)</ h3 >
< a href = "#" ondblclick = "alert('Welcome to Geeks for Geeks')" >
Double click on me </ a >
< a href = "#" ondblclick = "geeks()" >
Double click on me
</ a >
< script >
function geeks(){
document.getElementById("gfg")
.innerHTML='Welcome to GeeksforGeeks';
}
</ script >
< p id = "gfg" ></ p >
|
Output:

What does javascript:void(0) mean?
Using “javascript:void(0);” in anchor tag: Writing “javascript:void(0);” in anchor tag can prevent the page to reload and JavaScript functions can be called on single or double clicks easily.
Example:
html
< h1 style = "color:green" >GeeksforGeeks</ h1 >
< h3 >JavaScript:void(0)</ h3 >
< a href = "javascript:void(0);" ondblclick = "geek()" >
Double click on me </ a >
< p id = "gfg" >
</ p >
< script >
function geek() {
document.getElementById("gfg").innerHTML = "Welcome to GeeksforGeeks";
}
</ script >
|
Output:

What does javascript:void(0) mean?
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
23 Jan, 2023
Like Article
Save Article