I try to get height of the parent div of children elements.
I have a Parent
div with class="Parent" this have also n
children element like <div data-elementid="el_ryz-E9a349" class="row">
Parent
have a fix height: 220px
and I need to know if children element (n) <div data-elementid="el_ryz-E9a349" class="row">
appear in parrent height if not execute scrollIntoView()
to this children.
Important I can't delete this both elements, empty div
and <div class="container"
because affects my design.
...
const scrollToBottom = () => {
const elementNode = document.querySelector(`[data-elementid='${action.payload.id}']`);
const parentElementNode = elementNode.parentNode;
const elementsHeight = parentElementNode.offsetHeight;
const menuContainer = parentElementNode.parentNode.offsetHeight;
if (elementsHeight > menuContainer) {
elementNode.scrollIntoView({
behavior: 'smooth',
block: 'end',
});
}
};
setTimeout(scrollToBottom, 200);
...
It's obvious if I've n
children elements it's redundant to make elementNode.parentNode.parentNode.parentNode
to access Parent node to get height property.