Advanced go to TOP link

Submitted by:David Villa

Date added:29 April, 2015

Category:HTML

Advanced "Go to Top" link using JavaScript and HTML anchors

Tags: advanced link , html anchors

Code Snippet:

<!------>
<script type="text/javascript">
function init(){
document.getElementById('gtop').onclick = function(){
window.scrollTo(0,0);
return false;
}
}
onload=init;
</script>

<a name="top"></a>

<h1>Top position</h1>

<p>
A long text ....<br/>
A long text ....<br/>
A long text ....<br/>
A long text ....<br/>
A long text ....<br/>
A long text ....<br/>
</p>

<!-- create a long page -->
<br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/>

<p>
Last paragraph.
</p>

<br/>
<br/>

<a href="#top" id="gtop">Go to top</a>

<br/>
<br/>
 
 

Comments