+ 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

19th Oct 2020, 5:59 PM
Yash Arora🇮🇳
Yash Arora🇮🇳 - avatar
10 Antworten
+ 3
You need to wrap your item inside onload method onload = () => { new item("lol"); }
19th Oct 2020, 8:59 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 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";
19th Oct 2020, 6:22 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
19th Oct 2020, 9:02 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 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
19th Oct 2020, 9:08 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 1
Sumit Programmer😎😎 I did it but it still doesn't work
19th Oct 2020, 7:31 PM
Yash Arora🇮🇳
Yash Arora🇮🇳 - avatar
+ 1
I even tried query selector but it's not working
19th Oct 2020, 7:34 PM
Yash Arora🇮🇳
Yash Arora🇮🇳 - avatar
19th Oct 2020, 9:01 PM
Yash Arora🇮🇳
Yash Arora🇮🇳 - avatar
+ 1
Really I was so annoyed cause of this
19th Oct 2020, 9:01 PM
Yash Arora🇮🇳
Yash Arora🇮🇳 - avatar
+ 1
Sumit Programmer😎😎 can you tell me why it's needed doesn't js load after html?
19th Oct 2020, 9:03 PM
Yash Arora🇮🇳
Yash Arora🇮🇳 - avatar
+ 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
19th Oct 2020, 9:05 PM
Yash Arora🇮🇳
Yash Arora🇮🇳 - avatar