vanillajs-browser-helpers
Version:
Collection of convenience code snippets (helpers) that aims to make it a little easier to work with vanilla JS in the browser
30 lines (29 loc) • 894 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var manualInnerXml = function (XMLNode) {
var serializer = new XMLSerializer();
return Array
.from(XMLNode.childNodes, function (child) { return serializer.serializeToString(child); })
.join('');
};
/**
* Gets the inner XML structure as a string from a XML element
* (like innerHTML but for XML elements - eg. in SVG)
*
* @param XMLNode - The XML node to grab the inner XML structure from
* @return The inner XML structure
*
* @example
*
* ```ts
* // String is already HTML so it is returned as is
* innerXML(<svg><g><path /></g></svg>);
* // -> '<g><path /></g>'
* ```
*/
function innerXML(XMLElement) {
return XMLElement.innerHTML !== undefined
? XMLElement.innerHTML
: manualInnerXml(XMLElement);
}
exports.default = innerXML;