It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Close & Open Div

Close & Open Div

Postby hiyatran on Thu Oct 07, 2010 9:48 am

My code works but when I put an image in there my code doesn't work anymore.

<html>
<head>
<style type="text/css">
.planType{display:none; width:600px}

</style>

<script type="text/javascript">
<!--
function planTypeOpen(planID) {
document.getElementById('info_' + planID).style.display = "block";
document.getElementById('title_' + planID).innerHTML="<a href=\"javascript:planTypeClose('" + planID + "');\">Check this out" + "</a>";
}

function planTypeClose(planID) {
document.getElementById('info_' + planID).style.display = "none";
document.getElementById('title_' + planID).innerHTML="<a href=\"javascript:planTypeOpen('" + planID + "');\">Check this out" + "</a>";
}
//-->
</script>
</head>


<body>

<div id="title_1"><a href="javascript:planTypeOpen('1');">Check this out</a></div>
<div id="info_1" class="planType">
You can't see me...<br>
Or Can you??
</div>

</body>
</html>


any comments would be greatly appreciated.
hiyatran
 
Posts: 18
Joined: Mon Jun 21, 2010 1:53 am

Re: Close & Open Div

Postby webmaster on Thu Oct 07, 2010 12:16 pm

This is the code I often use as base for this.

Javascript:
Code: Select all
<script language=javascript type='text/javascript'>
function hidediv() {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById('hideShow').style.visibility = 'hidden';
}
else {
if (document.layers) { // Netscape 4
document.hideShow.visibility = 'hidden';
}
else { // IE 4
document.all.hideShow.style.visibility = 'hidden';
}
}
}

function showdiv() {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById('hideShow').style.visibility = 'visible';
}
else {
if (document.layers) { // Netscape 4
document.hideShow.visibility = 'visible';
}
else { // IE 4
document.all.hideShow.style.visibility = 'visible';
}
}
}
</script>


And for the HTML
Code: Select all
<div id="hideShow" ..etc>
My content
</div>
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden

Re: Close & Open Div

Postby HotNoob on Thu Oct 07, 2010 3:29 pm

the style.visibility one leaves white space where the content was, but if you want it to completely disappear, than you need to use the style.display attribute:

Code: Select all
 
function removeElement(value, id)
            {
                if(value == 1)
                    {
                        document.getElementById(id).style.display="";
                    }
                else if(value == 0)
                    {
                        document.getElementById(id).style.display="none";
                    }
            }
HotNoob
100+ Club
 
Posts: 169
Joined: Sun May 02, 2010 1:38 am


Who is online

Users browsing this forum: Google [Bot] and 2 guests