admin管理员组文章数量:1432001
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.
2 Answers
Reset to default 5I'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);
}
本文标签: javascriptConvert NodeList BACK to HTMLStack Overflow
版权声明:本文标题:javascript - Convert NodeList BACK to HTML - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745566291a2663778.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论