+ 1
I don't know why I can't select elements pls help me[solved]
https://code.sololearn.com/W8VYwH7GUWiu/?ref=app I am trying to select the div with class "list" in line 6 but getting an empty object
10 Answers
+ 3
You need to wrap your item inside onload method
onload = () => {
new item("lol");
}
+ 8
getElementsByClassName returns array of object (class) so if you want to grab class .list then you should need to do this
let a = getElementsByClassName(".list") //returns array of class
a[0].innerHTML = "some text";
+ 3
Yash Arora🇮🇳 welcome
+ 2
Onload methods indicated that your dom (html) loaded. And if you want any manipulation with html in js code then you need to wrap your code inside onload method
+ 1
Sumit Programmer😎😎 I did it but it still doesn't work
+ 1
I even tried query selector but it's not working
+ 1
Sumit Programmer😎😎 thanks
+ 1
Really I was so annoyed cause of this
+ 1
Sumit Programmer😎😎 can you tell me why it's needed doesn't js load after html?
+ 1
Sumit Programmer😎😎 Cause when I program on pc I put the script tag at bottom as suggested in sololearn and many other platforms as well . Does this mean that sololearns codeplayground does something else