0
<div id="wrapper" style="width:50px; overflow:hidden;">
  <span id="innerPart" style="white-space: nowrap; width: auto;">Lorem ipsum...</span>
</div>

Hello interwebs, I'm trying to get the width the innerPart would require to be fully displayed via JS. Tried using document.getElementById("innerPart").width; but it is just returning null

lukaszett
  • 1
  • 1

1 Answers1

0

Use document.getElementById("innerPart").offsetWidth

See this answer

If you wanted the width property it's off the style property. E.g. document.getElementById("innerPart").style.width

The difference being that offsetWidth is a computed property, it takes into account borders and padding whereas width doesn't. You may find that width is null and I'm assuming that is true if the width hasn't been specifically set by you.

Community
  • 1
  • 1
The Muffin Man
  • 19,585
  • 30
  • 119
  • 191