Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript 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, 05:08 AM
Authorized User
Join Date: Aug 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default accessing dynamic div width data


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 18th, 2005, 03:50 PM
nzakas's Avatar
Wrox Author
Join Date: Dec 2004
Posts: 217
Thanks: 0
Thanked 5 Times in 5 Posts

There are two ways:

div.offsetWidth - gives you the width of the div including border and margins.
div.clientWidth - gives you the width of the div excluding border and margins.

Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)

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
Dynamic div - width Ma7T Javascript How-To 2 August 18th, 2005 09:40 AM

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