1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <svg xmlns=
"http://www.w3.org/2000/svg">
3 <rect id=
"red" width=
"100" height=
"100" fill=
"green" />
4 <text id=
"text" x=
"10" y=
"120"></text>
5 <script type=
"text/javascript">
7 var green = document.getElementById('green');
8 // Note the use of createElement instead of createElementNS
9 var red = document.createElement(
"rect");
10 // HTML5 says createElement should lowercase the name and create it in the
11 // xhtml namespace. This means the created element is not an SVG element
12 // and therefore can't be appended to a SVG element.
13 green.setAttribute(
"width",
"100");
14 green.setAttribute(
"height",
"100");
15 green.setAttribute(
"fill",
"red");
16 green.ownerDocument.rootElement.appendChild(red);
17 document.getElementById('text').textContent =
"namespace of created rect: " + green.namespaceURI;