setAttribute()

The DOM method that sets an attribute on an element, with getAttribute() as its partner for reading one.

In more detail

element.setAttribute('aria-expanded', 'true') writes the attribute into the DOM, where CSS selectors, assistive technology and MutationObserver can all see it. Attribute values are always strings.

Related terms

Taught in

References