Source Code: (back to article)
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
.addStyle {
width: 500px;
background-color: yellow;
color: red;
text-align: center;
font-size: 20px;
}
</style>
</head>
<body>
<div id="divId">
<h1>W3Docs</h1>
</div>
<button onclick="myFunction()">Click on button</button>
<script>
function myFunction() {
document.getElementById("divId").className = "addStyle";
}
</script>
</body>
</html>