+ 5
How to make a button change the background in JavaScript?
please I've been trying to make this and I can't make the button do that, could you help me?
10 odpowiedzi
+ 13
<button onclick="function(){
element.style.background='black';
}">click</button>
the above code changes background of any element to black
by changing property of element
+ 8
I explained that in my code 'Changing Style'. Take a look!
+ 5
Thank you both 😁
+ 5
You can also change its background when hovered using simple HTML and CSS.
First you create the button in HTML:
<input type="button" id="button" value="Button">
Then you create the css for normal button:
#button {background-color:black;}
And finally the CSS for when its hovered:
#button:hover {background-color:blue;}
+ 3
1)u have to use onclick attribute invoking a function
and 2) u shud define the function such a way that it will change ur backgroundcolor
if u post ur code i can help u further
+ 3
michelle add a boolean that's set to true. now in click function check boolean is true or not and
if true change background
and set it to false
+ 2
yes take a look at Cezars code it has controls that set color of elements
it is nice
it has explanation too of
how it works.
+ 2
Wow👍
+ 2
I want to change my background and lock it
+ 1
document.getElementById("").style.background = "yourstyle"