Web APIs

Element.getAttribute()

Try the free JavaScript compiler

getAttribute reads an attribute string or null. DOM properties may reflect attributes with a different type. Boolean attributes are true by presence, not by the spelling of their value.

Formal Syntax & Structure

javascript syntaxjavascript
element.getAttribute(qualifiedName)

Parameters & Attributes

NameTypeDescription
qualifiedNamestringAttribute name.

Return Value

string | null

Attribute value or null.

Working Example

Example Snippetjavascript
const b=document.createElement("button");b.setAttribute("disabled","false");console.log(b.disabled,b.getAttribute("disabled"));
JavaScript Reference