getAttribute method
The getAttribute method reads
the value of a specified attribute
on a tag.
Syntax
element.getAttribute(attribute name);
Example
Let's output the content of the
value
attribute of an element:
<input id="elem" value="abcde">
let elem = document.querySelector('#elem');
let value = elem.getAttribute('value');
console.log(value);
The code execution result:
'abcde'
See also
-
the
setAttributemethod
that sets attributes -
the
removeAttributemethod
that removes attributes -
the
hasAttributemethod
that checks attributes