Skip to content

JavaScript void(0) onClick

  • by

Using JavaScript void(0) with onClick prevents the default action of an HTML element, such as a link or a button, when it is clicked. To prevent the page from reloading upon a single click, we can use JavaScript:void(0); within the anchor link.

JavaScript void(0) onClick example

Simple HTML example code won’t perform any default action and execute the JavaScript code alert('Hello World!') on click.

<!DOCTYPE html>

<button onClick="javascript:void(0); alert('JavaScript void(0) onClick')">Click me</button>



JavaScript void(0) onClick

Comment if you have any doubts or suggestions on this JS void topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading