Welcome to WebmasterWorld Guest from 54.234.153.186

Forum Moderators: open

Message Too Old, No Replies

Using Javascript to show/hide div but IE leaves space for hidden div

height:1 doesn't work...

     

dataguy

5:37 pm on Aug 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not much for Javascript, but I need to show & hide a form which contains a text area and a submit button. The form is displayed numerous times with different id's. The javascript I use for the show/hide is:

function showDiv( id ) {
document.getElementById(id).style.visibility = 'visible';
document.getElementById(id).style.height = '90px';
document.getElementById(id).focus();
}
function hideDiv( id ) {
document.getElementById(id).style.visibility = 'hidden';
document.getElementById(id).style.height = '1px';
document.getElementById(id).focus();
}

The problem is that space is still left where the hidden div is, so I added height:1px to the style of the divs, which took care of the problem for everything but Internet Explorer.

Is the a better way to do this that works with IE?

Thanks!

Demaestro

5:48 pm on Aug 13, 2009 (gmt 0)

WebmasterWorld Senior Member demaestro is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Instead of:
document.getElementById(id).style.visibility = 'hidden';

Try:
document.getElementById(id).style.display = 'none';

To show it:
document.getElementById(id).style.display = 'block';

DrDoc

7:04 pm on Aug 13, 2009 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



And, in this scenario, you can also ditch setting the height.

dataguy

7:41 pm on Aug 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perfect, thanks Demaestro!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month