<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <div>
        <div>
            <div></div>
            <div>2</div>
        </div>
    </div>
</div>
</div>
<script>
    const mainDiv = document.getElementsByTagName('div')
    let lastDiv
    const finLastDiv = (el) => {
        if(el.children[el.children.length - 1]) {
           finLastDiv(el.children[el.children.length - 1])
        }
        else {
          lastDiv = el
        }
    }
    finLastDiv(mainDiv[0])
    console.log(lastDiv)
    console.log(lastDiv.innerHTML)
</script>
</body>
</html>

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.