SBel
SBel

Reputation: 3361

object.style.height doesn't work

I've googled this but didn't find an answer, this is strange. In Javascript in Firefox when I do object.style.height it doesn't return anything. Would anybody know why?

In CSS I've put

#movable {
height: 100px;
....

In HTML I've put

<div id="movable">&nbsp;</div>

And in JS:

alert(movable.style.height);

Upvotes: 1

Views: 806

Answers (2)

Neil
Neil

Reputation: 55392

element.style is just a conversion of the element's style attribute into a scriptable object. If you haven't set any inline style on the element, you won't get anything back.

If you want to query the dimensions of an element, there are a number of ways, such as object.getBoundingClientRect().

Upvotes: 0

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114367

You're trying to get the element's CSS height. If there isn't one defined in the element's style, that's what you get.

If you want the physical height, use object.offsetHeight

Upvotes: 2

Related Questions