JSFiddle - React, Tailwind, and code Playground

HTML

<script src="http://dougneiner.s3.amazonaws.com/test/jquery.ui.widget.js"></script>

JavaScript

$.widget("test.recursive", {
    options: {
        parent: null
    },
    children: null,
    _create: function () {
        this.children = [];
        if (this.options.parent) {
            this.options.parent.children.push( this );
        }
    },
    addChild: function () {
        return $("<div>").recursive({ parent: this }).data('recursive');
    }
});
    
var d = $("<div>", { html: "Hi" }).recursive(), dd = d.data('recursive');
    
d.appendTo("body");

$("body").click( function () {
    $(this).append("<br />Running...");
   dd = dd.addChild(); 
});


var x = dd.addChild();

x.addChild();