JSFiddle - React, Tailwind, and code Playground
CSS
div {
display: grid;
border-left: 1px solid blue;
margin-left: 0.5em;
}
JavaScript
const docBody = document.getElementsByTagName('body')[0];
const elementConstructor = () => {
const root = document.createElement('div');
root.append("Click me if I'm the last one")
root.addEventListener('click', (e) => {
if (e.target !== root) return
root.append(elementConstructor())
});
return root;
}
docBody.append(elementConstructor());