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

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 01-30-2013, 07:04 PM   PM User | #1
RussFortyFour
New Coder

 
Join Date: Apr 2012
Posts: 16
Thanks: 5
Thanked 0 Times in 0 Posts
RussFortyFour is an unknown quantity at this point
Quick question, simple javascript... I think anyway

Hello coders,

I dont know any javascript yet but I would just like to know how to do one thing. Im using a bit of code to find the height of a <div> which is different depending on the amount of content it contains.

This is the code im using and its working fine:

Code:
<script language="javascript">

onload=function() {

var divh = document.getElementById('main-content').offsetHeight;

var divh = divh + 200;

// alert(divh +"px");

// document.write(divh);

 }

</script>

So heres the thing, what I need to do is take the value in the variable divh and echo it into the page as an inline css height attribute.

So for example:

Code:
<div style="height:<javascript value here>px;">

Site Content

</div>
Any help would be greately appreciated.

Thanks, R404

Last edited by RussFortyFour; 01-30-2013 at 07:07 PM..
RussFortyFour is offline   Reply With Quote
Old 01-30-2013, 07:17 PM   PM User | #2
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 952
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
That is not a (IMHO) good way of doing that. You want to get the element and set the property in JS, not use JS to write out the value.

Give the div an ID, and use

document.getElementById('theID').style.height = divh + "px";
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Users who have thanked WolfShade for this post:
RussFortyFour (01-30-2013)
Old 01-30-2013, 07:35 PM   PM User | #3
RussFortyFour
New Coder

 
Join Date: Apr 2012
Posts: 16
Thanks: 5
Thanked 0 Times in 0 Posts
RussFortyFour is an unknown quantity at this point
My Regards Mr.Wolfe
RussFortyFour 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 08:55 PM.


Advertisement
Log in to turn off these ads.