0

Is there a way to avoid scrolling page up on clicking a simple link such as the one given below:

<a href="#">Click Me</a>

3 Answers3

1

Try this one:

HTML

<div>Test</div>
<a href="javascript:void(0);">Click me</a>

CSS

div{
   height: 1000px;
}

The div is only for demonstration. jsfiddle

Mario Kurzweil
  • 490
  • 6
  • 11
1

You can prevent the default action in a JavaScript event handler with Event.preventDefault() like this:

$('#link').click(function(e){
     e.preventDefault();
});

(Assuming the link has the id link You said you use jQuery, so I used jQuery syntax here)

Demo

Reeno
  • 5,720
  • 11
  • 37
  • 50
0

Try the following one:

<a href="#!"> Click Me </a>
user1012181
  • 8,648
  • 10
  • 64
  • 106
  • 1
    Links like this will still change the page URL, resulting in an extra entry in the browser's history and causing the "back" button to simply remove the fragment from the URL instead of doing what the user expects. – Reeno Oct 13 '15 at 21:08