By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,453 Members | 932 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,453 IT Pros & Developers. It's quick & easy.

Finding a layer's width when the CSS is not set

Expert 100+
P: 392
Does anyone know a trick to get the width of a layer when its CSS width attribute is not set? The code below will return a value of null since the CSS attributes are not set. Does anyone know of a way to get the layer's width in this case?

Expand|Select|Wrap|Line Numbers
  2. <div id="someLayer" ></div>
  4. <script>
  5.     alert('Width: 'document.getElementById('someLayer').style.width):
  6. </script>
Mar 9 '09 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 5K+
P: 8,639
It should inherit the width of the nearest ancestor element, where this property is defined. if there's no width defined, it will take window width minus margins, paddings, borders and offsets.
Mar 9 '09 #2

Expert Mod 15k+
P: 16,027
Perhaps this is what you're looking for.
Mar 9 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.