Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <style> .democlass {color:red} </style> <body> <h1>HTML DOM Elements</h1> <h2>The setAttribute() Method </h2> <p>Set the first H1's class attribute to "democlass".</p> <script> const element = document.getElementsByTagName("H1")[0]; element.setAttribute("class", "democlass"); </script> </body> </html>