I have an object taken from the DOM who's actual offsetHeight I can not correctly get.
When trying to console.log the object to check the property, it does show the correct offsetHeight. But when I try to get the object.property, then the wrong value shows.
My code (using console.log for simplicity but using the values anywhere in a different way results in the same core problem):
function introBackgroundSize(){
let endpointElement = document.querySelector("div[data-bg--intro='endhere']");
console.log(endpointElement.offsetHeight); //logs 1636(px)
console.log(endpointElement); //opening to check shows offsetHeight 912(px) (the value I need)
console.log(endpointElement.offsetHeight); //logs 1636(px)
}
introBackgroundSize();
Looking for directions and possible reasons.
Tried using different values and different properties like scrollHeight and swapping around orders. But I keep receiving the wrong value.
What's odd is that it does show the right value in the object, so it's not like the element changes height before or after I try to get the value.
.offsetHeight()
value is an integer ex. 1636. Maybe what you observe of DOM object when rendered is the true height as a float ex. 1636.5648? When you "check the property" what exactly is "object.property"?