I'd like that a specific link goes to a certain header on another page. I know how to do it on the current page.
You need to use the href attribute to link to another page. The value of the href attribute is usually a URL pointing to a web page (like the one above). You can also link another HTML element or a protocol (for example, sending email), and you can execute JavaScript using the href attribute.
If you absolutely need to use JavaScript, one way is to find a link inside the div and go to its href when the div is clicked. This is with jQuery: $(". myBox").
Linking to an element on the same page Note: You can use href="#top" or the empty fragment ( href="#" ) to link to the top of the current page, as defined in the HTML specification.
Take a look at anchor tags. You can create an anchor with
<div id="anchor-name">Heading Text</div>
and refer to it later with
<a href="http://server/page.html#anchor-name">Link text</a>
You simply combine the ideas of a link to another page, as with href=foo.html
, and a link to an element on the same page, as with href=#bar
, so that the fragment like #bar
is written immediately after the URL that refers to another page:
<a href="foo.html#bar">Some nice link text</a>
The target is specified the same was as when linking inside one page, e.g.
<div id="bar"> <h2>Some heading</h2> Some content </div>
or (if you really want to link specifically to a heading only)
<h2 id="bar">Some heading</h2>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With