How to prevent a click on a ‘#’ link from jumping to the top of the page with HTML?

Spread the love

Sometimes, we want to prevent a click on a ‘#’ link from jumping to the top of the page with HTML.

In this article, we’ll look at how to prevent a click on a ‘#’ link from jumping to the top of the page with HTML.

How to prevent a click on a ‘#’ link from jumping to the top of the page with HTML?

To prevent a click on a ‘#’ link from jumping to the top of the page with HTML, we use the #! as the href value.

For instance, we write

<a href="#!" class="someclass">Text</a>

to set the href attribute to #! to prevent a click on a ‘#’ link from jumping to the top of the page.

Conclusion

To prevent a click on a ‘#’ link from jumping to the top of the page with HTML, we use the #! as the href value.

Leave a Reply

Your email address will not be published.