Javascript question

Out of context: Reply #3

  • Started
  • Last post
  • 21 Responses
  • CygnusZero40

    One last question. How do you take this script and make it so each item clicked closes all of the other open items. Right now you can expand all which I dont want. In the end it will look like this:

    <script type="text/javascript">
    function hideshow(which){
    if (!document.getElementById)
    return
    if (which.style.display=="block")
    which.style.display="none"
    else
    which.style.display="block"
    }
    </script>

    <a href="javascript:hideshow(document.getElementById('adiv1'))">Option 1</a>
    <div id="adiv1" style="font:24px bold; display: block">Option 1 description</div>

    <a href="javascript:hideshow(document.getElementById('adiv2'))">Option 2</a>
    <div id="adiv2" style="font:24px bold; display: block">Option 2 description</div>

    <a href="javascript:hideshow(document.getElementById('adiv3'))">Option 3</a>
    <div id="adiv3" style="font:24px bold; display: block">Option 3 description</div>

View thread