When can I read attributes such as offsetWidth of DOM elements

after you create a dom element in a javascript script and add it to the document with appendChild, when can you read attributes such as offsetWidth of the element?

the values of reading these attributes are all 0 before the element is rendered, so is there a timing or callback function to let me know that these attributes are valid?

like the hook function componentDidMount, in React, you can know exactly that the element has been rendered. What is its principle?

Thank you.

Apr.02,2021
After the

appendChild operation


appendChild is executed, the DOM can be read normally.

Menu