<!DOCTYPE html>
<html>
<head>
<style>
.mystyle {
width: 300px;
height: 100px;
background-color: coral;
color: white;
margin-bottom: 10px;
}
</style>
</head>
<body>
<p>Click the button to display the value of the class attribute of the div element below.</p>
<div id="myDIV" class="mystyle">
I am a DIV element with class="mystyle"
</div>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementsByClassName("mystyle")[0].className;
var y = document.getElementById("myDIV").className;
document.getElementById("demo").innerHTML = "Using getElementsByClassName: " + x + "<br>" + "Using getElementById: " + y;
}
</script>
</body>
</html>