Lightning Components: DOM-Functions behave different on new vs. existing record

This is because there are actually 2 instances of your div/component in the DOM tree after a new Account is created.

If you change your div to have class="te2" instead of an id and then in your click handler do:

var te2 = document.getElementsByClassName("te2");

You'll get back an array with both elements. The first element has clientHeight 0 because it is not visible (what you get back when you do your original getElementById), while the 2nd has the expected 19. I assume the first element is also not a valid component and thus not returned by cmp.find().getElement(), which would explain why Mohith's answer also works.

Originally, the copy of part of the DOM tree was kept around to support back button functionality but at this point it brings about such hard to track down differences in functionality like this that I would have to agree that it would probably be considered more of a bug than implementation detail.


cmp.find("te2").getElement()

I would use cmp.find() instead of document.getElement(). This is because cmp.find() is the native Lightning API for finding the DOM

To make this work, you have to add an aura:id like this to the div

<div aura:id="te2" id="te2">...</div>