/** * Creates an element with the specified namespace URI, qualified name, * attributes and children. * * @param String ns The namespace URI to use. * @param String tagName A string that specifies the type of element * to be created. * @param Object attributes An object containing key-value mappings for * attributes to be set on the newly * created element. * @param Array children An array containing child elements and/or * strings. Any strings will be inserted as text * nodes into the newly created element. Children * will be appended in array order. */ function createElementNS(ns, tagName, attributes={}, children=[]) { const elem = document.createElementNS(ns, tagName); Object.entries(attributes).forEach(([key, value]) => { elem.setAttribute(key, value); }); if(children) { for(let i=0; i