Change Element class Using JavaScript
home
Run
screen_rotation
fullscreen
cloud_download
navigate_before
<html> <head> <title>Javascript Demo</title> <script type='text/javascript'> function appendClass(){ document.getElementById("myId").className += " borderBlack"; } </script> <style type="text/css"> .borderBlack{ border:5px solid gray !important; } .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='appendClass()'>Change Class</a> </body> </html>
<html> <head> <title>Javascript Demo</title> <script type='text/javascript'> function appendClass(){ document.getElementById("myId").className += " borderBlack"; } </script> <style type="text/css"> .borderBlack{ border:5px solid gray !important; } .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='appendClass()'>Change Class</a> </body> </html>
Copyrights@tutorialsplane.com