Tryit Editor v2.3

Edit This Code:
<!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 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], Fri, 23 Jan 2015 08:28:27 GMT --> </html>
Result:
Try it Yourself - © w3schools.com