<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 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.getElementsByTagName("DIV")[0].className;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_element_classname1 by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Jan 2020 03:02:18 GMT -->
</html>