Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2012
    Posts
    16
    Thanks
    5
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    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".

  • Users who have thanked WolfShade for this post:

    RussFortyFour (01-30-2013)

  • #3
    New Coder
    Join Date
    Apr 2012
    Posts
    16
    Thanks
    5
    Thanked 0 Times in 0 Posts
    My Regards Mr.Wolfe


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •