Web Analytics Made Easy -
StatCounter hiding or viewing stuff - CodingForum

Announcement

Collapse
No announcement yet.

hiding or viewing stuff

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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>

    Comment

    Working...
    X