+ 1
which method is used to read value of an attribute?
2 Answers
+ 2
The method is: getAttribute (attributeName)
Example:
var x = document.getElementsByTagName("H1")[0].getAttribute("class");
gets the class of the first H1 element.
+ 1
Depends on what attribute the element has. If it's an id attribute and you want to access its value use getElementById('id').
If it's an element's class attribute value, use getElementsByClassName('class'). This will select one or more elements.
The other methods, of which one was mentioned by Nathan here, are querySelector('css selector') and querySelectorAll('css selector').