Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent page from going to the top when clicking a link

Tags:

html

How can I prevent the page from "jumping up" each time I click a link? E.g I have a link somewhere in the middle of the page and when I click it the page jumps up to the top.

like image 479
user1683645 Avatar asked Dec 15 '22 18:12

user1683645


1 Answers

Is the anchor href="#"? You can set it to href="javascript:void(0);" instead.

If you are going to a prevent default please use this one instead:

event.preventDefault ? event.preventDefault() : event.returnValue = false;

like image 194
David Nguyen Avatar answered Feb 06 '23 14:02

David Nguyen