-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdarkLight.html
More file actions
48 lines (42 loc) · 1.1 KB
/
darkLight.html
File metadata and controls
48 lines (42 loc) · 1.1 KB
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
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DarkLight</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<style>
.dark {
background-color: #444;
color: #fff;
}
.light {
background-color: #fff;
color: #444;
}
</style>
</head>
<body class="">
<h1>Dark Light Toggling</h1>
<button id="c">click to toggle background</button>
<script>
$(document).ready(function () {
$('#c').click(function () {
let bgColor = $.cookie("BgColor");
if (bgColor == 'dark') {
$.cookie("BgColor", "light");
$('body').removeClass('dark');
$('body').addClass($.cookie("BgColor"));
} else {
$.cookie("BgColor", "dark");
$('body').removeClass('light');
$('body').addClass($.cookie("BgColor"));
}
});
$('body').addClass($.cookie("BgColor"));
});
</script>
</body>
</html>