Create a DOM document from string, without JQuery

后端 未结 9 507
梦如初夏
梦如初夏 2020-12-05 14:12

We\'re looking for ways to create a DOM document in javascript from a string, but without using Jquery. Is there a way to do so? [I would assume so, since J

9条回答
  •  渐次进展
    2020-12-05 14:37

    fetch("index.html", {  // or any valid URL
        method: "get"
    }).then(function(e) {
        return e.text().then(e => {
            var t = document.implementation.createHTMLDocument("");
            t.open();
            t.write(e);
            t.close();
            return t;
        });
    }).then(e => {
        //  e will contain the document fetched and parsed.
        console.log(e);
    });
    

提交回复
热议问题