getAttribute method

The getAttribute method reads the value of a specified attribute on a tag.

Syntax

javascriptelement.getAttribute(attribute name);

Example

Let's output the content of the value attribute of an element:

html<input id="elem" value="abcde">
javascriptlet elem = document.querySelector('#elem');
let value = elem.getAttribute('value');

console.log(value);

The code execution result:

javascript'abcde'

See also