create a HTMLCollection

后端 未结 4 1430
半阙折子戏
半阙折子戏 2020-12-01 23:39

I\'m trying to shim Element.prototype.children which should return a HTMLCollection

There is a window.HTMLCollection

However

var h = new HTML         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 00:18

    I think this is the proper way of creating HTMLCollection, which is handled by the browser.

    var docFragment = document.createDocumentFragment();
    docFragment.appendChild(node1);
    docFragment.appendChild(node2);
    var myHTMLCollection = docFragment.children;
    

    Refs.:

    https://stackoverflow.com/a/35969890/10018427

    https://developer.mozilla.org/en-US/docs/Web/API/NodeList

    https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection

    https://www.w3schools.com/js/js_htmldom_nodelist.asp

提交回复
热议问题