Wiki ▸ [[API Reference]] ▸ [[Core]] ▸ Namespaces

SVG has a different namespace from HTML, so D3 provides a few tools to simplify dealing with namespaces.

# d3.ns.prefix

The map of registered namespace prefixes. The default value is:

  svg: "",
  xhtml: "",
  xlink: "",
  xml: "",
  xmlns: ""

Additional prefixes may be assigned as needed to create elements or attributes in other namespaces.

# d3.ns.qualify(name)

Qualifies the specified name, which may have a namespace prefix. If the name contains a colon (":"), the substring before the colon is interpreted as the namespace prefix, which must be registered in d3.ns.prefix; the return value is an object with space and local attributes containing the full namespace URL and the local name. For example, the result of qualify("svg:text") is:

{space: "", local: "text"}

If the name does not contain a colon, this function merely returns the input name. This function is used internally to decide whether to use a namespaced method (such as createElementNS) or a non-namespaced equivalent.