tags:

views:

62

answers:

6

How do you link (with <a>) so that the browser goes to certain subheading on the target page as opposed to the top?

+4  A: 

If there is an <a name="foo"> tag or any tag with an id (e.g., <div id="foo">), then you can simply append #foo to the URL. Otherwise, you can't arbitrarily link to portions of a page.

Here's a complete example: <a href="http://example.com/page.html#foo"&gt;Jump to #foo on page.html</a>

Daniel DiPaolo
A: 

You have two options:

You can either put an anchor in your document as follows:

<a name="ref"></a>

Or else you give an id to a any HTML element:

<h1 id="ref">Heading</h1>

Then simply append the hash #ref to the URL of your link to jump to the desired reference. Example:

<a href="document.html#ref">Jump to ref in document.html</a>
Daniel Vassallo
A: 

Here is how:

<a href="#go_middle">Go Middle</a>

<div id="go_middle">Hello There</div>
Sarfraz
You what? You've got a closing `</a>` after an opening `<div ...>` - not really sure what you're trying to do here.
Dominic Rodger
i copied my line of link and pasted below and forgot to close the div. Thanks anyways.
Sarfraz
+3  A: 

You use an anchor and a hash. For example:

Target of the Link:

 <a name="name_of_target">Content</a>

Link to the Target:

 <a href="#name_of_target">Link Text</a>

Or, if linking from a different page:

 <a href="http://path/to/page/#name_of_target"&gt;Link Text</a>
Michael Aaron Safyan
+1  A: 

W3 Schools have a simple guide here but yes - you use name attributes and the hash.

Chris W
+1  A: 

Just append a hash with an ID of an element to the URL. E.g.

<div id="about"></div>

and

http://mysite.com/#about

So the link would look like:

<a href="http://mysite.com/#about"&gt;About&lt;/a&gt;

or just

<a href="#about">About</a>
Felix Kling