Current location: Hot Scripts Forums » General Web Coding » JavaScript » Change width of div if another div is not present


Change width of div if another div is not present

Reply
  #1 (permalink)  
Old 12-03-04, 09:22 AM
hockeykid hockeykid is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Change width of div if another div is not present

Hello,

I have a div, #content, and floated next to it is #ads.

I have to give both divs a width because they're floated and many browsers don't like it if you float elements without a width.

But because #ads isn't going to be on every one of my pages, I need a way to get #content to stretch to the end of my #container if #ads is not there.

So here is my problem: How do I check if #ads is present on the page and then change the width of #content accordingly?

For example: If #ads is present, I would like #content to be 460px wide. If #ads is not present, I would like #content to be 580px wide. How can I accomplish this?

Also, I'll need to use the Box Model Hack (if you're familiar with CSS), so this may complicate the code a bit, but we can worry about that after).

Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 12-07-04, 02:25 AM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
I think the easiest way to do this would be something like this:

[code]
<div id="content" style="position:absolute;top:100;left:470;width:20 0;height:100;>My Text</div>
<div id="ads" style="position:absolute;top:100;left:10;width:460 ;height:100;>My Ads</div>

<script>
document.getElementById('content').style.width= (document.getElementById('ads') ? 460 : 580)+"px"

</script>
[code]

Just make sure the code runs after both (or one) of the tags have been inserted into the page like above.
Reply With Quote
  #3 (permalink)  
Old 12-08-04, 07:27 PM
hockeykid hockeykid is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Cool, thank you for your input.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 10:36 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.