<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.mystyle {
width: 100%;
padding: 25px;
background-color: coral;
color: white;
font-size: 25px;
box-sizing: border-box;
}
</style>
</head>
<body>
<p>Click the "Try it" button to add the "mystyle" class to the DIV element:</p>
<button onclick="myFunction()">Try it</button>
<div id="myDIV">This is a DIV element.</div>
<script>
function myFunction() {
var element, name, arr;
element = document.getElementById("myDIV");
name = "mystyle";
arr = element.className.split(" ");
if (arr.indexOf(name) == -1) {
element.className += " " + name;
}
}
</script>
</body>
<!-- Mirrored from www.w3schools.com/howto/tryit.asp?filename=tryhow_js_add_class_crossbrowser by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Jan 2020 02:38:50 GMT -->
</html>