According to JavaScript: The Definitive Guide: “Despite its name, innerHTML can be used with XML elements as well as HTML elements”.
However, when I actually attempt to access the innerHTML property of an XML Element object, undefined is returned:
var xml = $.ajax({url: "test.xml", async: false}).responseXML.documentElement;
console.log(xml.innerHTML); // displays "undefined" in console log
What is the explanation for this behavior?
test.xml:
<?xml version="1.0" encoding="utf-8"?>
<foo><bar>baz</bar></foo>
The explanation is that the book is wrong on this point.
XML elements in IE have a non-standard
xmlproperty that provides the equivalent ofinnerHTML. For other browsers you’ll need to use anXMLSerializer.