+ 3

Help with color input

Why is the word “hello” not changing color when I pick a color? And why am I console logging #000000 no matter what color I select? https://sololearn.com/compiler-playground/Wk8HrWduxZRT/?ref=app Thanks

20th Jun 2024, 5:18 AM
Zvi
Zvi - avatar
3 Antworten
+ 2
The correct way to write this code is: const e = document.getElementById("q"); const box = document.getElementById("box"); const changeclr=()=>{ console.log(e.value); box.style.color=e.value; }
20th Jun 2024, 10:01 AM
SoloProg
SoloProg - avatar
+ 1
SoloProg unfortunately, the inline function call in the html tab would still fail to find the javascript function in the javascript tab. one way is to migrate the js and put it in the html tab as internal js. The other way is to assign the eventListener in the javascript tab.
20th Jun 2024, 10:46 AM
Bob_Li
Bob_Li - avatar
+ 1
in sololearn by default js code is placed in header so, when this script get executed elements are not created. use window.onload when you set onclick = function, function must be defind before rendering the element. so you cannot place function inside window.onload
20th Jun 2024, 11:29 PM
Andrew [DEAD]
Andrew [DEAD] - avatar