+ 1

Can someone help (js)

Can someone help me make the checkbox in this code: https://code.sololearn.com/W2w4chDT1aGl/?ref=app Change the background to white when checked and if its not checked to be black I have tried the internet methods but they don’t do what i want them to do

12th Jan 2019, 7:40 PM
∞ Infinítє Сσdєr ∞
∞ Infinítє Сσdєr ∞ - avatar
4 Respuestas
+ 1
check if that's what you're looking for: https://code.sololearn.com/WAtP5g6s5ewz/#js
12th Jan 2019, 8:44 PM
MO ELomari
MO ELomari - avatar
+ 2
<head></head> <body bgcolor="black"><p style="color:black">Who turned the lights on?</p> <h1>Ghost text 1</h1> <br /><br /> <h1 class="two">Ghost text 2</h1> <br /><br /> <h1 class=" three">Ghost text 3</h1> <label class="switch"> <input type="checkbox" class="checked" id="check" > <span class="slider round"></span> </label> window.onload = function () { var theCheck = document.querySelector("#check"); theCheck.onchange=function(){ if(theCheck.classList.contains("checked")){ document.body.style.backgroundColor="black"; theCheck.classList.remove("checked"); } else { document.body.style.backgroundColor="white"; theCheck.classList.add("checked"); } } } Hello! It is solving of your problem)
12th Jan 2019, 8:10 PM
bondcoder
bondcoder - avatar
+ 2
thanks guys
12th Jan 2019, 8:51 PM
∞ Infinítє Сσdєr ∞
∞ Infinítє Сσdєr ∞ - avatar
+ 1
Use Jquery, it's so easy and simple. Here is an example for your problem, I used your code. You can copy and paste to see the effect. <head> <script src="https://code.jquery.com/jquery-3.1.1.js"></script> </head> <body bgcolor="black"><p style="color:black">Who turned the lights on?</p> <h1>Ghost text 1</h1> <br /><br /> <h1 class="two">Ghost text 2</h1> <br /><br /> <h1 class=" three">Ghost text 3</h1> <label class="switch"> <input class="check" type="checkbox" > <span class="slider round"></span> </label> <script> $(function (){ $(".check").click(function (){ $("body").css({background : "white"}); $("") }) }) </script>
12th Jan 2019, 8:31 PM
Houssein Elmi Hassan
Houssein Elmi Hassan - avatar