Get the string representation of a DOM node

前端 未结 11 2138
傲寒
傲寒 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:46

    Under FF you can use the XMLSerializer object to serialize XML into a string. IE gives you an xml property of a node. So you can do the following:

    function xml2string(node) {
       if (typeof(XMLSerializer) !== 'undefined') {
          var serializer = new XMLSerializer();
          return serializer.serializeToString(node);
       } else if (node.xml) {
          return node.xml;
       }
    }
    

提交回复
热议问题