+ 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
8 Answers
+ 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
+ 8
Calviղ , Mayank Dhillon Thanks for your help😊
+ 6
Im my example you can see bgcolor changung at button or at a interval of time.
+ 4
But it should work. It changes the background color into blue after 2 seconds
+ 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>
+ 2
💧Alex Tusinean🔥 for timing this is not working
+ 2
💧Alex Tusinean🔥 Ok I will check it