JSFiddle - React, Tailwind, and code Playground

by jonathon

HTML

<div>
    <a href="asd"></a>
    <p>
        <img/>
    </p>
</div>
<p></p>
<a></a>

CSS

ol, li{
    margin-left: 10px;
    list-style: disc;
}

JavaScript

function generateList(rootElement) {
    var rootElementItem = $("<li>" + rootElement.get(0).tagName + "</li>");

    if (rootElement.children().size() > 0) {
        var list = $("<ol />");
        rootElement.children().each(function() {
            list.append(generateList($(this)));
        });

        rootElementItem.append(list);
    }

    return rootElementItem;
}

var listOfElements = generateList($("body"));
$("body").append($("<ol/>").append(listOfElements));