Link to an element within the current page
You need to create an anchor for the link. The modern way of doing this is to give the appropriate element an id="Content"
attribute. The older way of doing this was to use <a name="Content"></a>
.
How to link to a div on another page?
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>
Link to a section of a webpage
your jump link looks like this
<a href="#div_id">jump link</a>
Then make
<div id="div_id"></div>
the jump link will take you to that div
Getting a link to go to a specific section on another page
I believe the example you've posted is using HTML5, which allows you to jump to any DOM element with the matching ID
attribute. To support older browsers, you'll need to change:
<div id="timeline" name="timeline" ...>
To the old format:
<a name="timeline" />
You'll then be able to navigate to /academics/page.html#timeline
and jump right to that section.
Also, check out this similar question.
Link to an element on the same page and have it centered in window
<head>
<script>
function change()
{
document.getElementById("myID").style.marginTop="100px";
}
</script>
</head>
<body>
<a href="#myID" onclick="change()">Link</a>
<div id="myID">Content that I would like in center of screen, rather than at the absolute top.sss
<pre>
s
s
s
s
s
s</pre>
</div>
</body>
Link to reload current page
I have been using:
<a href=".">link</a>
Have yet to find a case and/or browser where it does not work as intended.
Period means the current path. You can also use ..
to refer to the folder above the current path, for instance, if you have this file structure:
page1.html
folder1
page2.html
You can then in page2.html
write:
<a href="../page1.html">link to page 1</a>
EDIT:
I'm not sure if the behaviour has changed or if it was always like this, but Chrome (and maybe others) will treat periods as described above as regarding directories, not files. This means that if you are at http://example.com/foo/bar.html
you are really in the directory /foo/
and a href
value of .
in bar.html
will refer to /foo/
rather than bar.html
Think of it as navigating the file system in a terminal; you can never cd
into a file :)
EDIT 2:
It seems like the behaviour of using href="."
is not as predictable anymore, both Firefox and Chrome might have changed how they handle these. I wouldn't rely entirely on my original answer, but rather try both the empty string and the period in different browsers for your specific use and make sure you get the desired behaviour.
Related Topics
How to Style the Arrow of <Details> <Summary> Elements
Fire Onmouseover Event When Element Is Disabled
How to Pre-Populate HTML Form Input Fields from Url Parameters
Preserve Line Breaks in Textarea
Why Does Width and Height of a Flex Item Affect How a Flex Item Is Rendered
How to Avoid Flash of Unstyled Text (Fout) Even with Web Font Loader
How to Make a Div with Arrowlike Side Without CSS Border Tricks
Including a Interactive 3D Figure with Knitr
What Does "Semantically Correct" Mean
How to Escape HTML-Specific Characters in a String (Powershell)
How Move 'Nav' Element Under 'Navbar-Brand' in My Navbar
How to Always Show Up/Down Arrows for Input "Number"
What Is The Purpose for HTML's Tbody
CSS Margin: 0 Is Not Setting to 0
How to Change Svg Color When It Is an Encoded CSS Background Image