0

Please why doesn't this code work...I'm trying to change the color of the <div> element via click function

https://code.sololearn.com/WN1M3Q15lX2M/?ref=app

24th Apr 2020, 10:14 AM
Vic Okeke
5 ответов
+ 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.
24th Apr 2020, 10:38 AM
Ipang
+ 1
Tnx
24th Apr 2020, 12:11 PM
Vic Okeke
+ 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 ^^ */
24th Apr 2020, 11:15 PM
visph
visph - avatar
+ 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) */
24th Apr 2020, 11:21 PM
visph
visph - avatar
0
Wow..it actually works Thanks 😀😀
5th May 2020, 5:07 PM
Vic Okeke