screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <style> .my-class {background-color: yellow;} </style> <script> window.onload = function () { var body = document.body; var button = document.getElementById("my-button"); button.addEventListener("click", function () { body.classList.toggle("my-class"); }); }; </script> </head> <body> <h3>Javascript add class to body tag dynamically</h3> <button id="my-button">Toggle Class on Body</button> </body> </html>