Wednesday, February 20, 2008

How to link to location on the same page using HTML

How to create a links that can jump into specific section on a page? We can do it by using the Anchor Tag and the Name Attribute. That is simple and direct.
Below is the syntax:
<a name=”name_of_section”>Text to be displayed</a>
<a href=#name_of_section”>Text to be displayed</a>


For Example:
I put the line below at the top of this post
<a name=”top”></a>
To go back to the top of this post, I use the following line:
<a href=#top>Go to top of this post</a>
Go to top of this post

You can also link to a particular section on another page directly too; just add a # sign and the name of the anchor to the end of a URL. For Example, to link directly to section 2 (“w2”) of my previous post (with title “ASP .NET Web Service: “The request failed with HTTP status 401: Access Denied.” Error”), I use like this:
<a href="http://wec-library.blogspot.com/2008/02/asp-net-web-service-request-failed-with.html#w2”>Section 2 of Previous Post</a>
Section 2 of Previous Post

0 comments: