Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent screen from moving when clicking on <a href=></a>

Tags:

html

css

I'm using <a href> element along with :target css selector to show a <div> which by default is set to display:none. Problem is, that when I click on the link to show that <div>, it is automatically scrolling down my site towards that <div>.

Is there a way to stop the screen movement?

Unfortunately I am not yet proficient in anything besides CSS and HTML.

like image 693
Czulu Avatar asked Dec 08 '13 19:12

Czulu


Video Answer


2 Answers

You can use event.preventDefault() to avoid this. Something like this:

$('a.yourclass').click(function(e)
{
    //your code
    e.preventDefault();
});

OR:

<a href="javascript:void(0)" onclick="somefunction(); return false;">link</a>
like image 150
Rahul Tripathi Avatar answered Oct 13 '22 13:10

Rahul Tripathi


in the link enter:

<a href="javascript:void();">Link here</a>
like image 5
scooterlord Avatar answered Oct 13 '22 11:10

scooterlord