homepage Welcome to WebmasterWorld Guest from 50.16.165.62
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Using Javascript to show/hide div but IE leaves space for hidden div
height:1 doesn't work...
dataguy




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

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




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

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




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

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

dataguy




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

Perfect, thanks Demaestro!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved