+ 1
Javascript?
Lets see this code: let box = document.querySelector("div"); let input = document.querySelector("input"); input.addEventListener(input. () = { box.style.border-radius = input.value; box.style.background-color = input.value; }) whats wrong here
4 Antworten
+ 1
in sololearn, js is placed inside head. So when that js code is getting interpreted div is not created.
--> place code after body. or
--> place code inside window.onload = (){here}
+ 1
As andrew said you have to use this in your code. I made a minor correction:
window.onload = () => {
//code here
}
After you put your JS code inside the function, you'll get an error “box” is not defined.
To fix this, you need to give your div an ID. Like this:
<div id="box"></div>
+ 1
This will help you:
//Lets see this code:
let box = document.querySelector("div");
let input = document.querySelector("input");
input.addEventListener("input", () => {
//box.style.border-radius
box.innerText = ""
box.style.borderRadius = input.value + "px";
//box.style.background-color
box.style.backgroundColor = "#" + input.value + input.value + "9";
})
https://sololearn.com/compiler-playground/W8NAYkJYHzLa/?ref=app
0
I think you’re referring to this code?
https://sololearn.com/compiler-playground/WrKRPUn4E40N/?ref=app