docs.rodeo

MDN Web Docs mirror

Document: createAttribute() method

{{ ApiRef("DOM") }} 

The Document.createAttribute() method creates a new attribute node, and returns it. The object created is a node implementing the {{domxref("Attr")}}  interface. The DOM does not enforce what sort of attributes can be added to a particular element in this manner.

[!NOTE] The string given in parameter is converted to lowercase.

Syntax

createAttribute(name)

Parameters

Return value

A {{domxref("Attr")}}  node.

Exceptions

Examples

const node = document.getElementById("div1");
const a = document.createAttribute("my_attrib");
a.value = "newVal";
node.setAttributeNode(a);
console.log(node.getAttribute("my_attrib")); // "newVal"

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN