Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript change background color on click [closed]

Can you show me Javascript that allows you to change the background color of the page to another color. For example, I have a blue background color and I want to change it to green. The color must be changed when the user presses a button that triggers the event. I saw that it exists on many sites but I could not write the code I write in REACTJS I would love to have your help

Thanks...

like image 478
Manuela Arecibo Avatar asked Dec 03 '22 16:12

Manuela Arecibo


1 Answers

If you want change background color on button click, you should use JavaScript function and change a style in the HTML page.

function chBackcolor(color) {
   document.body.style.background = color;
}

It is a function in JavaScript for change color, and you will be call this function in your event, for example :

<input type="button" onclick="chBackcolor('red');">

I recommend to use jQuery for this.

If you want it only for some seconds, you can use setTimeout function:

window.setTimeout("chBackColor()",10000);
like image 160
Saeed Rahmani Avatar answered Dec 05 '22 06:12

Saeed Rahmani