Results 1 to 2 of 2

Thread: how to find div width at page load......

  1. #1
    Join Date
    Sep 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to find div width at page load......

    hey frnds,

    m new learner of js and jquery......
    i have at html structure like above......

    <div style="width:965px">
    <div style="width:100%" align="center">
    <div style="width:365px" align="center">
    <div id="test">

    </div>
    </div>
    </div>
    </div>

    now what i want...
    i want to find the div "test" width at page load event (<body onload="findwidth();")..
    result should be 365 px....
    but when i m using
    var width=document.getelementbyid('test').offsetWidth;
    than it show the undefined in width...

    any help.....

    Inderjeet Singh Khalsa

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by inderjeetsinghsethi View Post

    document.getelementbyid('test')
    is not a function. I think you want:

    Code:
    document.getElementById('test')
    Anyways, this works just fine:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript">
    function findwidth(){
    	var width = document.getElementById('test').offsetWidth;
    	alert(width);
    }
    </script>
    </head>
    <body onload="findwidth();">
    <div style="width:965px">
    <div style="width:100%" align="center">
    <div style="width:365px" align="center">
    <div id="test">
    
    </div>
    </div>
    </div>
    </div>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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