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