0
I want to make html code on button click change background color simultaneously
My friend has made a project that if he clicks on button the background image or background color changes on button click. If he click for first time then the color would be sky color on second click it will become darker and on third click it will become black. Can any body help me please.
5 Respostas
+ 3
Firstly create an array of colors. In javascript
var colors = ["skyblue","blue","black"]
And then the button in the html
<button onclick="change()">Change</button>
Then in javascript,
Define the change function
var I=0
function change(){
I++
document.body.style.backgroundColor=colors[I]
}
See this code
https://code.sololearn.com/WeayjyJNvynY/?ref=app
+ 3
I++
if (I == colors.length) I=0 // reset
+ 1
ARYAN Khuman you welcome.
0
I want to make a website in which one rockets is in between of the page, 2 buttons up and down, if I click up button background will change Fromm one to 2nd if I click again up button bg changes again to 3rd and if I click down button bg changes to 2nd and if I click down button again bg changes to 1
0
Thanks bro