CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   HTML & CSS (http://www.codingforums.com/forumdisplay.php?f=13)
-   -   Possible to stop page jumping when # link is used? (http://www.codingforums.com/showthread.php?t=289859)

davidwhite 03-15-2013 02:54 PM

Possible to stop page jumping when # link is used?
 
Hello,

When I use an <a href> link internally with #, the page jumps to the top. Is there any way to stop this?

Thanks

Frankie 03-15-2013 03:00 PM

Yep, don't include the href part in the <a>. So your link will look like this, for the time being:

Code:

<a>Link text</a>

StevenHu 03-15-2013 10:57 PM

What I did was give the <a href> an id. Then the id went into the #:

<a href="#something" id="something">link is here</a>

AndrewGSW 03-15-2013 11:15 PM

Quote:

Originally Posted by davidwhite (Post 1320645)
Hello,

When I use an <a href> link internally with #, the page jumps to the top. Is there any way to stop this?

Thanks

Better would be not to use a link, if it is not linking to anything..

felgall 03-16-2013 07:36 AM

Where you see code that reads <a href="#">something</a> the # is supposed to be replaced with whatever page you intend to have the link take people to if it isn't overriden by JavaScript - you should never actually use it in a live web page. If it isn't intended to be a link to anywhere for those without JavaScript then don't code an <a> at all in the HTML.

The one time when you might actually set the href to # is if the link is added from JavaScript and the script overrides the default action and you want the href there so that the browser adds it to the link collection and not the anchor collection. For example:

Code:

var a = document.createElement('a');
a.href="#";
a.onclick = function() {functiontorun(); return false;};
a.innerHTML = 'click here to run the function';
document.getElementById('addPoint').appendChild(a);


webdevs 03-16-2013 08:32 AM

Please remove that # sign.

tempz 03-17-2013 03:12 AM

Code:

<a href="javascript:void(0)" onclick="Index">

AndrewGSW 03-17-2013 03:29 AM

Quote:

Originally Posted by tempz (Post 1320999)
Code:

<a href="javascript:void(0)" onclick="Index">

This approach is discouraged, and "javascript:" is deprecated/not required.


All times are GMT +1. The time now is 09:03 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.