0
Please why doesn't this code work...I'm trying to change the color of the <div> element via click function
5 Réponses
+ 4
Use 'onchange' event of the <select> rather than 'onclick' on the <option>.
Create a boolean variable (let's name it <bright>), and toggle its value every time the <select> onchange eventhandler is invoked. When <bright> is true set background colour white, otherwise set it black.
+ 1
Tnx
+ 1
var modern=document.getElementsByClassName("mode")[0];
/*
getElementsByClassName return an array-like object (even if only one item inside): notice the 's' of 'element' conversely to getElementById ^^
*/
+ 1
function change() {
if (light.selected==true) {
modern.style.backgroundColor="white";
}
else {
modern.style.backgroundColor="black";
}
}
/*
you need to check the 'selected' property, rather than the element itself (wich will ever be equals to true :P)
*/
0
Wow..it actually works
Thanks 😀😀