0

Javascript Reset button Function

Imagine you have a border and a button that changes the background color of the border. js code: document.getElementById("some id").style.backgroundColor = "red"; How to make a button that can reset the background color of the border? getElementById("some id").reset() doesent do the thing.

25th Aug 2016, 10:04 PM
Faris S
Faris S - avatar
9 odpowiedzi
+ 1
Clone your button and change red to white.
26th Aug 2016, 7:53 AM
Zen
Zen - avatar
0
getElementById("someId").style.border = "none";
25th Aug 2016, 10:17 PM
Dick
0
That removes the border. Doesn't affect bg color.
25th Aug 2016, 10:41 PM
Faris S
Faris S - avatar
0
document.getElementById("someId").style.backgroundColor = "none"; doesn't work as well
25th Aug 2016, 10:43 PM
Faris S
Faris S - avatar
0
your default background color for border?
26th Aug 2016, 2:18 AM
Dick
0
How many buttons? One or two? If you want to use only one button, let's closure it. Need to know default bg color for your border. Hard to give you specific answer if I can't see your html code. There are many tips and tricks to manipulate DOM.
26th Aug 2016, 2:27 AM
Dick
0
default background color is white
26th Aug 2016, 3:04 AM
Faris S
Faris S - avatar
0
<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <p id="counter">0</p> <div id="demo">Hello World!</div> <button onclick="add()">Add/Hide Border</button> <script> function add() { var counter = document.getElementById("counter").innerHTML; counter++; document.getElementById("counter").innerHTML = counter; if (counter % 2 == 0) { document.getElementById("demo").style.borderColor = "white"; } else { document.getElementById("demo").style.borderColor = "red"; } } </script> </body> </html>
27th Aug 2016, 7:49 AM
Dick
0
you can hide the counter, using css, display: none;
27th Aug 2016, 7:51 AM
Dick