Q_24598697: Click to open new part of page and scroll to it

This example show how you can click on a link that links to an anchor and at the same time make that part of the document visible. This is handy for one-view pages where the initial page is not scrollable.

This page will remain online for future reference. The original question can be viewed at Experts-Exchange, but requires (free) membership. More information about me, about how this site is maintained and about how to use these pages for yourself, check out the opening page.

click to see this demo

Use the following code:

Call the two functions in the onclick of a a-href and set the #name to the same name as the id. This will both scroll to the block and make it visible.

<script type="text/javascript>
    function openBlock(id){
        var obj = document.getElementById(id);
        obj.style.display = "block";
        return true;			
    }
    function closeBlock(id) {
        var obj = document.getElementById(id);
        obj.style.display = "none";
        return true;			
    }
</script>

<-- example href as used below -->
<a href="#readfurther" onclick="openBlock('readfurther')">Read further>/a>