Walk through Shadow and Light DOM recursively

前端 未结 1 1853
[愿得一人]
[愿得一人] 2020-12-06 22:45

I am trying to walk through the shadow and light DOM recursively (looking for the first input, wherever it may be). This didn\'t seem to be such a hard

相关标签:
1条回答
  • 2020-12-06 23:21

    The solution is to wait that polymer is ready:

    document.addEventListener('polymer-ready', function() {
        recursiveWalk(document.body, function (node) {
            console.log(node.nodeName);
        });
    })
    

    and to use the shadowDom property:

    if ('shadowRoot' in node &&  node.shadowRoot) {
        var done = recursiveWalk(node.shadowRoot, func);
        if (done) {
           return true;
        }
    }
    

    http://jsfiddle.net/za1gn0pe/7/

    0 讨论(0)
提交回复
热议问题