Element className Property - Get the class names of an element with multiple classes: - Javascript DOM

Javascript examples for DOM:Element className

Description

Element className Property - Get the class names of an element with multiple classes:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
.mystyle {/*from  w ww . ja  v a  2s.co m*/
    width: 500px;
    height: 50px;
}

.test {
    background-color: blue;
}

.example {
    text-align: center;
    font-size: 25px;
    color: black;
    margin-bottom: 10px;
}
</style>
</head>
<body>

<div id="myDIV" class="mystyle test example">
I am a DIV element with multiple classes
</div>

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

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myDIV").className;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials