0
Why is the text "New Paragraph" not visible in the output? It should appear additionally next to "Old Paragraph".
3 Antworten
+ 2
you need to put [0] after getElementsByClassName("my-par") because it is "elements" it gives html collection so putting [0] takes the first element or occurrence of that class element.
const myPar = document.getElementsByClassName("my-par")[0];
myPar.innerHTML += " New Paragraph";
+ 2
getElementsByClassName in this Element wont work because getElementByClassName is nothing is JavaScript
0
Thank you that works!
But if I write Element instead of Elements, it should work then without [0] isnt it? Because it doesnt