how to get html attribute js code example Example: get element attribute javascript var x = document.getElementsByTagName("H1")[0].getAttribute("class");