MDN self-hosted library · e01.org

Namespaces crash course

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

html
<svg xmlns="http://www.w3.org/2000/svg">
  <!-- more tags here -->
</svg>
js
document.createElementNS("http://www.w3.org/2000/svg", "rect");
js
rect.getAttributeNS(null, "x");
js
elt.getAttributeNS("http://www.w3.org/1999/xlink", "href");
js
elt.setAttributeNS(
  "http://www.w3.org/1999/xlink",
  "xlink:href",
  "other-doc.svg",
);
js
const SVG_NS = "http://www.w3.org/2000/svg";
const XLINK_NS = "http://www.w3.org/1999/xlink";
const image = document.createElementNS(SVG_NS, "image");
image.setAttributeNS(null, "width", "100");
image.setAttributeNS(null, "height", "100");
image.setAttributeNS(XLINK_NS, "xlink:href", "flower.png");