Element className Property - check class name - Javascript DOM

Javascript examples for DOM:Element className

Description

Element className Property - check class name

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
.mystyle {/*  w  w w. j  a v  a 2s  .  c  o  m*/
    width: 300px;
    height: 50px;
    text-align: center;
    background-color: coral;
    color: white;
    margin-bottom: 10px;
}
</style>
</head>
<body>

<div id="myDIV" class="mystyle">
I am a DIV element
</div>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {
    var x = document.getElementById("myDIV");

    if (x.className === "mystyle") {
        x.style.fontSize = "30px";
    }
}
</script>

</body>
</html>

Related Tutorials