Dark theme for Js apps
There will be no specific role of HTML code in this part.
Just write your code in the body tag. Here for the sake of simplicity, we will choose the body element that will contain our content. You have to just create a button in HTML.
HTML part
<h2>Toggle between Dark Light Mode</h2>
<p>Hey don't look at me like this , I am just a boring text and nothing more than that.</p>
<button onclick="enabledmode"> Toggle to dark mode</button>
ALERT: text with this // are all one liner js comments
CSS Part
body{
background-color: white;
color: black;
}
//also create a .dark_mode class to toggle to darkmode
Js part
//we will create a function enabledmode() to execute our plan
function enabledmode(){
// create a variable in body element
var element = document.body
//use classList.toggle DOM element to toggle between two classes.
element.classList.toggle("dark_mode")
}
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home