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.
9 odpowiedzi
+ 1
Clone your button and change red to white.
0
getElementById("someId").style.border = "none";
0
That removes the border. Doesn't affect bg color.
0
document.getElementById("someId").style.backgroundColor = "none"; doesn't work as well
0
your default background color for border?
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.
0
default background color is white
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>
0
you can hide the counter, using css, display: none;