Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 16th, 2005, 06:23 AM
Authorized User
 
Join Date: Aug 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic div - width

 Hi,

I have a div (div1) with no width specified as it contains dynaic data and expands to fit the data in.

I want to place another div (div2) beside it to the right - so on the same y pos as div1 but the x pos = (div1 width) + 5px

how do you access the div width of div1

div = document.getElementById(id)
divWidth = div.style.width;

doesn't return anything as the width element is dynmaic.....
But there must be a way...

 
Old August 16th, 2005, 10:09 AM
Authorized User
 
Join Date: Aug 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Answer:

function getDivWidth(id)
{

        range = document.body.createTextRange();
        Div = document.getElementById("id");

        range.moveToElementText(Div);

        alert(range.boundingWidth);
}

 
Old August 18th, 2005, 09:40 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I believe you can also use offsetWidth or the clientWidth.

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Sizing Div Width with window resizing javs Javascript 1 March 20th, 2008 01:13 AM
IE div columns width glitch discgolfer BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 4 February 23rd, 2006 05:51 PM
Dynamic Page width bmurphy BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 January 16th, 2006 04:56 PM
accessing dynamic div width data Ma7T Javascript 1 August 18th, 2005 03:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.