Concepts Used: toggleClass()
Features:
- Switch page between light & dark theme
<!DOCTYPE html>
<html>
<head>
<title>Dark Mode Toggle</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
body { transition: 0.5s; }
.dark { background: black; color: white; }
</style>
</head>
<body>
<h2>Dark Mode Example</h2>
<button id="toggle">Toggle Dark Mode</button>
<script>
$(document).ready(function(){
$("#toggle").click(function(){
$("body").toggleClass("dark");
});
});
</script>
</body>
</html>
Explanation:
.toggleClass()
switches between normal and dark theme.
Leave a Reply