Table of Contents

<HTMLElement>.setAttr()

Sets an attribute value of an Element. If the attribute does not exist, it will be created.

Usage:
HTMLElement = Element.setAttr(attrName, attrValue)
Member of:
HTMLElement
Parameters:
  1. attrName – the name of the attribute to set/change (required).
  2. attrValue – the value to set (required).
Returns:
The HTMLElement it was called on, thus allowing for command chaining.

Examples

Simple example:

const it = document.getElementById('item');
it.setAttr('foo', 'bar'));

See also

More information