javascript - Convert NodeList BACK to HTML - Stack Overflow

I'm using docx.js, which converts docx to html5 in the browser. The function convertContent output

I'm using docx.js, which converts docx to html5 in the browser. The function convertContent outputs a NodeList. The issue is I need an HTML/XML string, not a NodeList.

Is there any way to convert a NodeList back into HTML? There are plenty of examples of going the other way or converting it to an array, but none on how to convert it back to HTML.

I'm using docx.js, which converts docx to html5 in the browser. The function convertContent outputs a NodeList. The issue is I need an HTML/XML string, not a NodeList.

Is there any way to convert a NodeList back into HTML? There are plenty of examples of going the other way or converting it to an array, but none on how to convert it back to HTML.

Share Improve this question edited Feb 15, 2014 at 2:54 sinθ asked Feb 15, 2014 at 2:41 sinθsinθ 11.5k26 gold badges89 silver badges124 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 5

I'm a bit unclear on your question (specifically I need HTML5)

If you want the string representation this will create a string of the html for each node in the list

var html = Array.prototype.reduce.call(nodes, function(html, node) {
    return html + ( node.outerHTML || node.nodeValue );
}, "");

Update: fix textnodes showing up as undefined

Try placing this in console on this site

var htmlstr = Array.prototype.reduce.call($("div")[43].childNodes, function(html, node) {
    return html + ( node.outerHTML || node.nodeValue );
}, "");

console.log(htmlstr);

Several methods available for NodeList, one being values().

let list = document.body.childNodes; //<-- returns NodeList
for (const value of list.values()) {
  myTarget.querySelector("#my-target-element").append(value);
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745566292a4633412.html

相关推荐

  • javascript - Convert NodeList BACK to HTML - Stack Overflow

    I'm using docx.js, which converts docx to html5 in the browser. The function convertContent output

    17小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信