Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-15-2013, 02:54 PM   PM User | #1
davidwhite
New Coder

 
Join Date: Nov 2011
Posts: 27
Thanks: 4
Thanked 0 Times in 0 Posts
davidwhite is an unknown quantity at this point
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
davidwhite is offline   Reply With Quote
Old 03-15-2013, 03:00 PM   PM User | #2
Frankie
Regular Coder

 
Join Date: Sep 2011
Posts: 284
Thanks: 3
Thanked 32 Times in 32 Posts
Frankie is an unknown quantity at this point
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>
__________________
Frank

How to: Target IE in, Position in, Center in, Create a Fixed ('Sticky') Footer with, and Create a Drop-Down/Fly-Out Menu with CSS: Website Laten Maken Amsterdam.
Frankie is offline   Reply With Quote
Old 03-15-2013, 10:57 PM   PM User | #3
StevenHu
Regular Coder

 
Join Date: Jun 2011
Location: CA
Posts: 105
Thanks: 0
Thanked 10 Times in 10 Posts
StevenHu is an unknown quantity at this point
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>
__________________
Steve Husting
http://iphonedevlog.wordpress.com
StevenHu is offline   Reply With Quote
Old 03-15-2013, 11:15 PM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Quote:
Originally Posted by davidwhite View Post
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..
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 03-16-2013, 07:36 AM   PM User | #5
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,448
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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);
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 03-16-2013, 08:32 AM   PM User | #6
webdevs
New Coder

 
Join Date: Nov 2012
Location: India
Posts: 52
Thanks: 0
Thanked 3 Times in 3 Posts
webdevs is an unknown quantity at this point
Please remove that # sign.
webdevs is offline   Reply With Quote
Old 03-17-2013, 03:12 AM   PM User | #7
tempz
Regular Coder

 
Join Date: Jul 2012
Location: London
Posts: 436
Thanks: 4
Thanked 80 Times in 80 Posts
tempz is an unknown quantity at this point
Code:
<a href="javascript:void(0)" onclick="Index">
tempz is offline   Reply With Quote
Old 03-17-2013, 03:29 AM   PM User | #8
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Quote:
Originally Posted by tempz View Post
Code:
<a href="javascript:void(0)" onclick="Index">
This approach is discouraged, and "javascript:" is deprecated/not required.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:29 PM.


Advertisement
Log in to turn off these ads.