Javascript get div width

  • Tdotwire
  • Proficient
  • Proficient
  • User avatar
  • Joined: Jul 18, 2004
  • Posts: 486
  • Loc: Toronto
  • Status: Offline

Post April 15th, 2005, 2:59 pm

ok I am having a problem in regards to achieving the width of a div tag

the div tag is dynamic, so its content can change.

Now what would the javascript code be to get the width of the div.

document.getElementById("div_id").style.width doesn't seem to work and the offsetwidth command doesn't work either

how would you do this?

thanks
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post April 15th, 2005, 2:59 pm

  • RichB
  • Guru
  • Guru
  • User avatar
  • Joined: May 17, 2003
  • Posts: 1121
  • Loc: Boston
  • Status: Offline

Post April 15th, 2005, 4:35 pm

This can be a bit tricky depending on the details. This thread discusses some of the issues involved.
Moderator Remark: updated broken link
Free Programming Resources
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13458
  • Loc: Florida
  • Status: Offline

Post October 22nd, 2010, 2:06 am

Looking back, it's nice to see that all these years later getting the width of an element can be as simple as the following with libraries such as jQuery. :D

JAVASCRIPT Code: [ Select ]
var width = $('#element_id').width();
Strong with this one, the sudo is.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 124 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.