Skip to content

Element.getAttr method

Element › getAttr

Official

Gets an attribute from the element.

Signature:

getAttr(qualifiedName: string): null | string

Parameters:

Parameter Type Description
qualifiedName string The name of the attribute to get.

Returns: null | stringThe value of the attribute.

Example:

const element = createEl('p');
element.setAttr('data-foo', 'bar');
console.log(element.getAttr('data-foo')); // bar