Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    hiding or viewing stuff

    i want to hide or view something ( a div perhaps). could somebody write or give me a script to do this?
    Computers are simple for the complex mind, yet complex for the simple mind

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can use:
    style="display:none;

    if you want 2 buttons, one that shows, one that hides:

    <script>
    function showhide(divname,disp) {
    document.getElementById(divname).style.display=disp;
    }
    </script>

    <a href="javascript: showhide('mydiv','none');">HIDE</a>
    <a href="javascript: showhide('mydiv','');">SHOW</a>
    <div id="mydiv">This is the div I wish to show/hide.</div>

    Or if you want only one button

    <script>
    function showhide(divname) {
    if (document.getElementById(divname).style.display=="") {
    document.getElementById(divname).style.display="none";
    }
    else if (document.getElementById(divname).style.display=="none"){
    document.getElementById(divname).style.display="";
    }
    }
    </script>

    <a href="javascript: showhide('mydiv');">SHOW/HIDE</a>
    <div id="mydiv" style="display:;">This is the div I wish to show/hide.</div>

    Also if you want the same as the previous, but to change the word of the link:

    <script>
    function showhide(divname,what) {
    if (document.getElementById(divname).style.display=="") {
    document.getElementById(divname).style.display="none";
    }
    else if (document.getElementById(divname).style.display=="none"){
    document.getElementById(divname).style.display="";
    }
    if (document.getElementById(what).innerHTML=="HIDE") {
    document.getElementById(what).innerHTML="SHOW";
    }
    else if (document.getElementById(what).innerHTML=="SHOW"){
    document.getElementById(what).innerHTML="HIDE";
    }
    }
    </script>

    <span onclick="showhide('mydiv','hs');" id="hs">HIDE</span>
    <div id="mydiv" style="display:;">This is the div I wish to show/hide.</div>


  •  

    Posting Permissions

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