HTMLify
ToggleButton.html
Views: 523 | Author: shubh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | // Toggle Button to switch light theme to dark.. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Toggle Button</title> <style> .dark{ background-color: black; color: white; } .light{ background-color: white; color: black; } </style> </head> <body> <button id="mode">Change Mode</button> <p>Hi javascript...</p> <script> let btnmode=document.querySelector("#mode"); let body=document.querySelector("body"); let currmode = "light"; btnmode.addEventListener("click", () =>{ if(currmode==="light"){ currmode="dark"; body.classList.add("dark"); body.classList.remove("light"); } else{ currmode="light"; body.classList.add("light"); body.classList.remove("dark"); } }); </script> </body> </html> |