Change Element class Using JavaScript
home
Run
screen_rotation
fullscreen
cloud_download
navigate_next
<html> <head> <title>Javascript Demo</title> <script type='text/javascript'> function changeClass(){ document.getElementById("myId").className = "YellowBg"; } </script> <style type="text/css"> .YellowBg{ background:yellow; } .blueBg{ background:blue; } </style> </head> <body> <div style="height:100px;width:100px;border:1px solid green;" class='blueBg' id="myId"></div> <a href='javascript:void(0);' onclick='changeClass()'>Change Class</a> </body> </html>
<html> <head> <title>Javascript Demo</title> <script type='text/javascript'> function changeClass(){ document.getElementById("myId").className = "YellowBg"; } </script> <style type="text/css"> .YellowBg{ background:yellow; } .blueBg{ background:blue; } </style> </head> <body> <div style="height:100px;width:100px;border:1px solid green;" class='blueBg' id="myId"></div> <a href='javascript:void(0);' onclick='changeClass()'>Change Class</a> </body> </html>
Copyrights@tutorialsplane.com