Reputation: 822
I am using angular 5 where in a component I have one method
onFullScreen : function (event){ console.log(event[0]) }
Here, when I do console.log(event[0])
, this will return this
This returns a HTMLDivElement, now I want to get the height property in my onFullScreen()
method. How to get it?
Upvotes: 2
Views: 5329
Reputation: 18292
The best way to get the height of an element (and lots of other layout-related properties) is to use getBoundingClientRect
(https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect).
So you can do this:
const height = event[0].getBoundingClientRect().height;
Upvotes: 3
Reputation: 44
You can try this:
var height = document.getElementById('element').style.height;
Since the height is defined in inline styles for this element, this would work.
Warning: this does not work if height is not explicitly defined in css but calculated based on content or outer box.
Upvotes: 1