Get the string representation of a DOM node

前端 未结 11 2122
傲寒
傲寒 2020-12-01 03:56

Javascript: I have the DOM representation of a node (element or document) and I\'m looking for the string representation of it. E.g.,

var el = document.creat         


        
11条回答
  •  北海茫月
    2020-12-01 04:45

    I have wasted a lot of time figuring out what is wrong when I iterate through DOMElements with the code in the accepted answer. This is what worked for me, otherwise every second element disappears from the document:

    _getGpxString: function(node) {
              clone = node.cloneNode(true);
              var tmp = document.createElement("div");
              tmp.appendChild(clone);
              return tmp.innerHTML;
            },
    

提交回复
热议问题