+ 1

Help! My getElementsByClassName is not working

Help! My getElementsByClassName is not working https://code.sololearn.com/WpRT0Ma22vm8/?ref=app I have tried getElementsByClassName, ById but have not output anything. please help me shed more light on this

16th Sep 2018, 5:18 PM
ij888
ij888 - avatar
8 Respostas
+ 6
put your script in the html document using the <script> js <script> tag no need for using the window onload then
16th Sep 2018, 5:49 PM
D_Stark
D_Stark - avatar
+ 3
document.getElementsByClassName() returns an array of elements with such class name. To change the text of any element in the array, specify an index for it. Eg var payload = document.getElementsByClassName('row1') payload[0].innerHTML = 'text' Don't also forget to add window.onload = function (){ // Your Code }
16th Sep 2018, 5:43 PM
Dlite
Dlite - avatar
+ 3
The starter function makes sure that your DOM is fully setup or loaded before executing the JS code. Else your JS code will run without getting any element with the specified class name
16th Sep 2018, 5:47 PM
Dlite
Dlite - avatar
+ 2
You should add window.onload. You can see the code here https://code.sololearn.com/WXSa5gDVS8RG/?ref=app
16th Sep 2018, 5:35 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
That's if the script tag is at the bottom part of the <body> element
16th Sep 2018, 5:50 PM
Dlite
Dlite - avatar
+ 1
yo D_Stark Ya'iko thanks. I almost forgot I was using the soloLearn code auditor and not a fully scaffolded web project
16th Sep 2018, 6:16 PM
ij888
ij888 - avatar
+ 1
or I guess I can also use the script tags in the HTML of the SL code editor
16th Sep 2018, 6:35 PM
ij888
ij888 - avatar
0
I remember having used the getElementsByClassName without a starter function. is there a reason it must be included?
16th Sep 2018, 5:44 PM
ij888
ij888 - avatar