+ 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
8 Réponses
+ 6
put your script in the html document using the <script> js <script> tag no need for using the window onload then
+ 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
}
+ 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
+ 2
You should add window.onload. You can see the code here
https://code.sololearn.com/WXSa5gDVS8RG/?ref=app
+ 1
That's if the script tag is at the bottom part of the <body> element
+ 1
or I guess I can also use the script tags in the HTML of the SL code editor
0
I remember having used the getElementsByClassName without a starter function. is there a reason it must be included?