Do elements before they are part of the dom have the width and height set properly? ie if I create a div containing markup can I measure its intended width and height without appending it to the dom?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t formally know the answer, but a little gedankenexperiment lets us see that it can’t, in general, happen. If you create an HTML element with a fixed width and height, then yes – you can know the width and height.
However, if you don’t specify them (or they might not be obeyed), then the width and height are always going to be calculated by the contextual position of the fragment in the DOM; for example, a DIV with
width: 50%cannot know it’s actual width until it is added to the DOM and laid out – there’s no other way to answer “50% of what?”.