Source Code:
(back to article)
<!DOCTYPE html> <html> <head> <title>Title of the document</title> <style> .text-class { color: green; font-size: 40px; } </style> </head> <body> <button id="w3Button" type="button" onclick="clickFunction()">Click on button</button> <p id="w3Text">Welcome to W3Docs!</p> <script> function clickFunction() { // Select element and set attribute document.getElementById("w3Text").setAttribute("class", "text-class"); } </script> </body> </html>
Result:
Report an issue