This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

createAttributeNS

Summary

Creates a reference to an attribute object that is associated with an XML namespace.

Method of dom/Documentdom/Document

Syntax

var attribute = document.createAttributeNS(namespace, name);

Parameters

namespace

Data-type
String

The name of the desired namespace or a null value if no namespace is desired.

name

Data-type
String

The name of the desired attribute.

Return Value

Returns an object of type DOM NodeDOM Node

The created attribute.

Examples

//create a "lang" attribute associated with a namespace
var attr = document.createAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang");
//assign a value to the attribute
attr.nodeValue = "es-us";
//apply the attribute to the documentElement (e.g., the XML document's root node)
document.documentElement.setAttributeNodeNS(attr);

Notes

createAttributeNS is an XML DOM method and is supported only for XML documents.

Related specifications

DOM Level 3 Core
Recommendation

See also

Related pages

Attributions