How about this?
let height = 0
let node = document.querySelector('DIV_N')
while(true) {
height += node.getBoundingClientRect().height
if (node.classList.contains('DIV_1')) break
node = node.previousSibling
}
document.querySelector('.DIV_X').style.height = height + 'px'
CLICK HERE to find out more related problems solutions.