Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-23-2009, 10:33 PM   PM User | #1
questionable
Regular Coder

 
Join Date: Jun 2005
Posts: 153
Thanks: 26
Thanked 0 Times in 0 Posts
questionable is an unknown quantity at this point
Collapsing a <div> when contents are hidden

Hello,

I have the following scenario:
+-----------------------------------------+
|``````````````Main Div````````````````|
|+-------------------+-------------------+|
||````little div 1```` |````little div 2`````||
||`````````````````| ```````````````` ||
||`````````````````| ```````````````` ||
|+-------------------+-------------------+|
+------------------------------------------+

I have this script call in my jQuery:
Code:
$("#littlediv1").click($("#littlediv2").toggle())
Which automatically will either hide or unhide "little div 2" when "little div 1" is clicked.

Which turns my screen into this:
+-----------------------------------------+
|``````````````Main Div````````````````|
|+-------------------+``````````````````|
||````little div 1```` |``````````````````|
||`````````````````| ```````````````` `|
||`````````````````| ```````````````` `|
|+-------------------+``````````````````|
+------------------------------------------+

I do not know the size of "little div 1" because of variable data. But is there a way to make "Main Div" automatically collapse when this data is hidden so that it would look like this?
+---------------------+
|``````Main Div``````|
|+-------------------+|
||````little div 1```` ||
||`````````````````||
||`````````````````||
|+-------------------+|
+---------------------+
Also it would re-expand when "little div 1" is clicked again.

Is there a jQuery collapse div or a css collapse attribute I can use for this?
questionable is offline   Reply With Quote
Old 12-23-2009, 10:53 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
You say "collapse", but you really mean resize the width, since collapsing is a vertical thing. You can change the width of the div with the .css() function.

http://docs.jquery.com/CSS/css#namevalue
__________________
Fumigator is offline   Reply With Quote
Old 12-28-2009, 05:50 PM   PM User | #3
questionable
Regular Coder

 
Join Date: Jun 2005
Posts: 153
Thanks: 26
Thanked 0 Times in 0 Posts
questionable is an unknown quantity at this point
.css() worked great I just need to determine .attr("width") to determine the width and then use .css("width") to change the width of the other one.
questionable is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:50 PM.


Advertisement
Log in to turn off these ads.