def walkChildren(elem):
    JS("""
    var parent = @{{elem}};
    var child = @{{getFirstChild}}(@{{elem}});
    var lastChild = null;
    var stack = [];
    var parentStack = [];
    return {
        'next': function() {
            if (child == null) {
                throw @{{StopIteration}};
            }
            lastChild = child;
            var firstChild = @{{getFirstChild}}(child);
            var nextSibling = @{{getNextSibling}}(child);
            if(firstChild != null) {
               if(nextSibling != null) {
                   stack['push'](nextSibling);
                   parentStack['push'](parent);
                }
                parent = child;
                child = firstChild;
            } else if(nextSibling != null) {
                child = nextSibling;
            } else if(stack['length'] > 0) {
                child = stack['pop']();
                parent = parentStack['pop']();
            } else {
                child = null;
            }
            return lastChild;
        },
        'remove': function() {
            parent['removeChild'](lastChild);
        },
        __iter__: function() {
            return this;
        }
    };
    """)
Walk an entire subtree of the DOM.  This returns an
dataset/ETHPy150Open pyjs/pyjs/pyjswidgets/pyjamas/DOM.browser.py/walkChildren