All Posts by Email, Once a Week

Media Temple logo

CSS-Tricks is brought to you in part by Media Temple, the web hosting that we both use and recommend.

How to apply back to top link in get element by id function?

  • # October 2, 2009 at 8:22 am

    Im a little new to java/css/html, and recently coded my first site. I set up my portfolio site ( http://www.jonyablonski.net/ ) to allow for javascript to switch content, allowing for all material to be contain upon a single page using this function:

    function switchContent(pageNum) {
    document.getElementById("content").innerHTML = aryPages[pageNum];

    My question is, how do I code a ‘back to top’ link on necessary content when all the page info is contained within the javascript info, and not the body?

    # October 2, 2009 at 9:38 am

    Well ultimately the source code does HAVE a <body> and <html> element. So if you can find where those get generated and give one or the other an ID value, any link that #links to that ID value will jump to the top of the page.

    # October 3, 2009 at 11:30 am

    thanks chris!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed