How to make an anchor tag to do nothing?

Last updated 4 years, 2 months ago | 5500 views 75     5

HTML | Make an anchor tag to do nothing | href="javascript:void(0);"

To prevent reloading a page when a link clicked is something like preventing the default behavior of an element.
It can be achieved by providing "javascript:void(0)" in "href" attribute.

<a href="javascript:void(0)">Click Here</a>

The "javascript:void(0)" make the anchor tag "href" value undefined and make its behavior as plain text.

To know more about MSD Webdock




The anchor tag click can also be prevented by simply using "return false" in "onclick" event, like so:

<a href="#" onclick="return false;">Click Here</a>



See the Example

In the example, There is four anchor tag with each having different property and value. jump page to the top

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	<!-- Refress the page -->
    <a href="">Click Here</a>
	<!-- Jump page to the top  -->
	<!-- Add # at the end of the url -->
	<a href="#">Click Here</a>
	<!-- Do nothing -->
	<a href="#" onclick="return false;">Click Here</a>
	<!-- Do nothing -->
	<a href="javascript:void(0)">Click Here</a>