html
html
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
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h3 class="headline">Toggle Button<h3>
<input type="checkbox" id="checkbox" value="false">
<label for="checkbox">
<div class="switch">
<span class="slider" ></span>
<div>
</label>
<script>
var x = document.getElementsByTagName("body")[0];
document.querySelector('#checkbox').addEventListener("click",function()
{
//console.log("test2");
var check = document.querySelector('#checkbox').checked;
if(check)
{
x.style.backgroundColor ="wheat";
}
Enter to Rename, Shift+Enter to Preview
css
css
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
*{
padding:0;
margin:0;
}
body {
display:flex;
justify-content:center ;
align-items: center ;
min-height:100vh;
}
.switch{
position:relative ;
height:35px;
width:68px;
border-radius:20px;
display:inline-block ;
background-color: #CCCCCC;
cursor: pointer;
}
#checkbox{
Enter to Rename, Shift+Enter to Preview
js
js
1
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run