javascript - How to get the height of a height-adaptive element?
phpcn_u15822017-05-16 13:43:33
0
5
572
The height of my element box is not set and is expanded by the subset content. How to get its height? All methods such as height are 0. Is there any way to get the actual height?
The values obtained are all 0 because the height is not set. What I want is the actual height displayed after the web page is loaded, including subsets
The first possibility is that js is executed before rendering is completed. . Obtaining 0 The second possibility is that the child elements are all floating or absolutely positioned. The outermost layer has no height The third possibility is that the wrong element is obtained, is the js written wrong?
You can delay for a while before getting the height of the content, for example like this
clientHeight, scrollHeight, offsetHeight
innerHeight, outerHeight
Basically there is always one that suits you
The values obtained are all 0 because the height is not set. What I want is the actual height displayed after the web page is loaded, including subsets
The first possibility is that js is executed before rendering is completed. . Obtaining 0
The second possibility is that the child elements are all floating or absolutely positioned. The outermost layer has no height
The third possibility is that the wrong element is obtained, is the js written wrong?
It should be caused by executing the code to obtain the height before the element is rendered.