i want to hide or view something ( a div perhaps). could somebody write or give me a script to do this?
Announcement
Collapse
No announcement yet.
hiding or viewing stuff
Collapse
X
-
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