JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<div>
<p id="para1"></p>
</div>
</div>
<p id="para2"></p>
JavaScript
function getLeaves(element) {
if (element.children.length === 0) {
return [element];
}
var leaves = [];
for(var i = 0, l = element.children.length; i < l; i++) {
leaves.push.apply(leaves, getLeaves(element.children[i]));
}
return leaves;
}
console.log(getLeaves(document.body));