Edit This Code:
See Result »
<!DOCTYPE html> <html> <head> <style> .mystyle { width: 500px; height: 50px; } .test { background-color: lightblue; } .example { text-align: center; font-size: 25px; color: black; margin-bottom: 10px; } </style> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?73c27e26f610eb3c9f3feb0c75b03925"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </head> <body> <p>Click the button to display the class names of the div element.</p> <div id="myDIV" class="mystyle test example"> I am a DIV element with multiple classes </div> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myDIV").className; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
Result: