DotDragnet
May 24, 2012, 06:53:28 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Mobile users - Our forum is Tapatalk enabled. http://www.tapatalk.com/
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Simple Javascript (Probably) - How To Hide (Collapse) Elements  (Read 493 times)
Dom
Hero Member
*****
Posts: 1681


Taster of pasities. Clanger of both pots AND pans.


DominicNeagle
View Profile Awards
« on: August 25, 2011, 07:52:30 AM »

Hi all,

Simple Javascript issue, but as I don't use Javascript so much I thought I'd ask here.

I've got some <div> elements on my page that divide up my content into sections (as you might expect) and I've got some Javascript that shows/hides the <div> elements using code similar to the following:

Code:
document.getElementById("some-div-element").style.visibility = "hidden";

This works and all, but although it hides the element, it leaves a bloody great gap where the content used to be. So if I have multiple sections hidden in the middle of the page, there's just a load of whitespace where the <div> elements used to be.

So my question - when you hide elements, how do you "collapse" them so that when they're hidden, they don't still take up lots of space on the page?

I'm using IE for this, so it only needs to work for IE. Thanks!
Logged

Jem
Sr. Member
****
Posts: 469



jemjabella jemjabella
View Profile WWW Awards
« Reply #1 on: August 25, 2011, 08:11:27 AM »

http://girlswhogeek.com/tutorials/2007/show-and-hide-elements-with-javascript
Logged

oi.
Dom
Hero Member
*****
Posts: 1681


Taster of pasities. Clanger of both pots AND pans.


DominicNeagle
View Profile Awards
« Reply #2 on: August 25, 2011, 08:16:01 AM »

I'm torn. On the one hand, I'm glad there's an answer to my problem, but on the other hand, I'm not sure I want to have "girls who geek" showing up in my web history at work. Tongue Tongue

Seriously, though, thanks for the help (and shameless self-promotion... I like it!)
Logged

Dom
Hero Member
*****
Posts: 1681


Taster of pasities. Clanger of both pots AND pans.


DominicNeagle
View Profile Awards
« Reply #3 on: August 25, 2011, 08:22:20 AM »

EDIT: What a ninny - it does work. I changed the code, then didn't save the page before refreshing it in IE. #FoolishBoy

Uh oh, spagettio - it doesn't work.

It hides the elements OK, but it's still leaving whitespace where the "hidden" <div> elements are.
« Last Edit: August 25, 2011, 08:24:34 AM by Dom » Logged

Jem
Sr. Member
****
Posts: 469



jemjabella jemjabella
View Profile WWW Awards
« Reply #4 on: August 25, 2011, 09:16:57 AM »

Then you probably have a height set on your hidden div or something like that. Need more code.

Edit: didn't see your edit Tongue
Logged

oi.
Dom
Hero Member
*****
Posts: 1681


Taster of pasities. Clanger of both pots AND pans.


DominicNeagle
View Profile Awards
« Reply #5 on: August 25, 2011, 09:19:44 AM »

Yeah it's all good now, ta!
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!