- How do I make it so if yes button clicked change colour?
- Is using .onclick the best option for this?
- Am I doing it the optimal way?
Thanks.
html:
<body>
<div id="box"></div>
<button id="yes">yes</button>
<button id="no">no</button>
<script src="js/script.js"></script>
</body>
css:
#box {
width: 200px;
height: 200px;
background-color: red;
}
js:
function Choice () {
var box = document.getElementById("box");
var yes = document.getElementById("yes");
var no = document.getElementById("no");
if (yes.clicked == true) {
box.style.backgroundColor = "red";
} else if (no.clicked == true) {
box.style.backgroundColor = "green";
} else {
box.style.backgroundColor = "purple";
};
};
Choice ();
Aucun commentaire:
Enregistrer un commentaire