Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. Document
  4. createAttributeNS()

Document: createAttributeNS() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

TheDocument.createAttributeNS() method creates a new attribute nodewith the specified namespace URI and qualified name, and returns it.The object created is a node implementing theAttr interface. The DOM does not enforce what sort of attributes can beadded to a particular element in this manner.

Syntax

js
createAttributeNS(namespaceURI, qualifiedName)

Parameters

namespaceURI

A string that specifies thenamespaceURI to associate with the attribute. Some important namespace URIs are:

HTML

http://www.w3.org/1999/xhtml

SVG

http://www.w3.org/2000/svg

MathML

http://www.w3.org/1998/Math/MathML

qualifiedName

A string that specifies the name of attribute to be created.Thename property of the created attribute is initialized with the value ofqualifiedName.

Return value

The newAttr node.

Exceptions

NamespaceErrorDOMException

Thrown if thenamespaceURI value is not a valid namespace URI.

InvalidCharacterErrorDOMException

Thrown if thequalifiedName value is not a validXML name; for example, it starts with a number, hyphen, or period, or contains characters other than alphanumeric characters, underscores, hyphens, or periods.

Examples

js
const node = document.getElementById("svg");const a = document.createAttributeNS("http://www.w3.org/2000/svg", "viewBox");a.value = "0 0 100 100";node.setAttributeNode(a);console.log(node.getAttribute("viewBox")); // "0 0 100 100"

Specifications

Specification
DOM
# dom-document-createattributens

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp