+ 11

How can we make background as it is white after clicking on some button or after sometime in web code?

I want to display the background white after sometime from the execution of code. How can I do it using HTMl, JavaScript or CSS

22nd Dec 2018, 5:18 PM
Prajakta
Prajakta - avatar
8 Antworten
+ 12
Why use jQuery, while we have more simple way in JavaScript? Faster response too. 😁 <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <input type="button" onclick="chg()" value="press to change color"> <script> function chg() { document.body.style.backgroundColor = "red"; } </script> </body> </html> https://code.sololearn.com/Wn89jWELYkZC/?ref=app
23rd Dec 2018, 1:56 AM
Calviղ
Calviղ - avatar
+ 8
Calviղ , Mayank Dhillon Thanks for your help😊
23rd Dec 2018, 2:39 AM
Prajakta
Prajakta - avatar
+ 6
Im my example you can see bgcolor changung at button or at a interval of time.
23rd Dec 2018, 7:51 AM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
23rd Dec 2018, 7:46 AM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 4
But it should work. It changes the background color into blue after 2 seconds
23rd Dec 2018, 7:54 AM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 2
If you mean how to change background color on clicking a button then you can use this <!DOCTYPE html> <html> <head> <title>Page Title</title> <script src="https://code.jquery.com/jquery-3.1.1.js"></script> </head> <body style="background-color:white;"> <input type="button" id="btn1" value="press to change color"> <script> $(document).ready(function() { $("#btn1").on("click", function(){ $("body").css("background-color","red"); }); }); </script> </body> </html>
22nd Dec 2018, 5:46 PM
Mayank Dhillon
Mayank Dhillon - avatar
+ 2
💧Alex Tusinean🔥 for timing this is not working
23rd Dec 2018, 7:53 AM
Prajakta
Prajakta - avatar
+ 2
💧Alex Tusinean🔥 Ok I will check it
23rd Dec 2018, 7:56 AM
Prajakta
Prajakta - avatar