Edit This Code:
See Result »
<!DOCTYPE html> <html> <body> <h2 class="example">A heading with class="example"</h2> <p>A paragraph with class="example".</p> <p>Click the button to add a background color to the first element in the document with class="example".</p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { document.querySelector(".example").style.backgroundColor = "red"; } </script> </body> </html>
Result: