Javascript get div width

  • Tdotwire
  • Proficient
  • Proficient
  • User avatar
  • Posts: 486
  • Loc: Toronto

Post 3+ Months Ago

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
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

This can be a bit tricky depending on the details. This thread discusses some of the issues involved.
Moderator Remark: updated broken link
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

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();

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: sisindia01, spageopriya and 59 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.