Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to do what should be some the most basic html, but it's not working for me. Here is my code:

<a name="rocket"></a>
<div>
<h3>The Title</h3>
<p>some text</p>
</div>

I want to use the anchor name to fly down the contact page to the correct section.

When I use a link within the contact page like this:

<a href="#rocket">click here</a>

it works fine. But i want to come from another page and then fly down. So I am using this:

<a href="http://mysite.com/contact#rocket">click here</a>

but it seems to add a slash after contact and redirect to http://mysite.com/contact/#rocket, which means that it stays at the top of the contact page instead of flying down.

Does anyone know why this is happening? If you could point me in the right direction, I'd be grateful.

Thanks,

Yukon

ps, i have read all similar questions on this site, but they don't help me.

share|improve this question
3  
Is the anchor's href attribute really hardcoded (as HTML) like that, or is that the expected output of something? –  Johannes Pille May 8 '13 at 22:17
1  
    
thx again Andrew. In case anyone else is bashing their head against the wall with the same problem, the trailing slash causes all the trouble, so try mysite.com/contact/#rocket instead of mysite.com/contact/#rocket Probably a noob mistake, but i thought I'd share it. –  Yukon Cornelius May 9 '13 at 0:48
add comment

1 Answer

It is okay that the URL changes to http://mysite.com/contact/#rocket, but you should change the way you are defining your anchor on the target page.

Instead of using this method

<a name="rocket"></a>
<div>
<h3>The Title</h3>
<p>some text</p>
</div>

You should add an ID to the content you want to jump to like this:

<div id="rocket">
<h3>The Title</h3>
<p>some text</p>
</div>

This way your HTML markup is cleaner and there isn't an extra <a> element for the jump.

share|improve this answer
    
+1. Worth to mention. –  Johannes Pille May 8 '13 at 23:55
    
Thanks Ben, I will do that. –  Yukon Cornelius May 9 '13 at 0:46
1  
Or <h3 id="rocket" tabindex="0">. –  toscho May 9 '13 at 4:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.