Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go to #div box JavaScript

Tags:

html

anchor

Maybe jQuery, maybe not, but how do i do so like when you click on a link eg. FAQ it goes to the FAQ div box? I mean if its on the bottom then you just click on that link and then it goes to it..

Wikipedia have it.. http://en.wikipedia.org/wiki/USA The links in the "Contents".. when you click you get to it..

like image 572
Karem Avatar asked Feb 12 '10 21:02

Karem


2 Answers

That's not Javascript, those are anchor links. See: http://www.w3.org/TR/html401/struct/links.html

Basically, you'd link as such:

<a href="#FAQ">FAQ</a>

Then above the content you're linking to:

<a name="FAQ" />

Alternatively, you could use the same link and set the ID of the FAQ section header to "FAQ", like so:

<h1 id="FAQ">FAQs</h1>
like image 105
Matt Brunmeier Avatar answered Sep 29 '22 18:09

Matt Brunmeier


First, add an id to the HTML element. This will serve as the anchor.

For example:

id="mybox"

Now simply add a link to #mybox on that page. E.g. example.com/index.html#mybox

<a href="#mybox">Box</a>

As mentioned these are not anything to do with javascript; it is not required for this.

like image 22
user258634 Avatar answered Sep 29 '22 17:09

user258634