SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Netherlands
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question show-hide script help needed.

    Hi,

    For a hobby site, I found this script somewhere on the net and I'd like it to work the other way around. The content has to show and the visitor has to click to hide it.
    Could someone help me please? I'm a total Java-newbie...

    TIA
    Jaap

    Here's the code:

    in <head>tag
    <script type="text/javascript">
    <!--
    var storedDiv = null;
    function getDiv(oID) {
    if(document.getElementById) {
    return document.getElementById(oID);
    } else if( document.all ) {
    return document.all[oID];
    } else { return null; }
    }
    window.onload = function () {
    for( var i = 0, y; y = getDiv('ans'+i); i++ ) {
    y.style.display = 'none';
    }
    };
    function toggleInfo(oID) {
    var oDiv = getDiv(oID); if( !oDiv ) { return; }
    oDiv.style.display = (oDiv.style.display=='none') ? 'block' : 'none';
    if( storedDiv && storedDiv != oDiv ) { storedDiv.style.display = 'none';
    } storedDiv = oDiv;
    }
    //--></script>


    in <body>tag
    <span style="cursor: hand; cursor: pointer" onclick="toggleInfo('ans0');">
    >> Hide/show content
    </span><br><br>
    <div id="ans0">

    content

    </div>

  2. #2
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Netherlands
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up problem solved

    solution: using a different script...

    <script type="text/javascript">
    /* This goes in the head section */
    window.onload = function() { document.getElementById('hideable').style.display = 'block'; }

    function toggle(link, divid) {
    var div = document.getElementById(divid);
    if (div.style.display == 'none') {
    div.style.display = 'block';
    link.innerHTML = 'Hide Sponsors';
    } else {
    div.style.display = 'none';
    link.innerHTML = 'Show Sponsors';
    }
    }
    </script>


    >> <a href="#hideable" onclick="toggle(this, 'hideable'); return false;">Hide Sponsors</a><br><br>
    <div id="hideable">

    content

    </div>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •