0

Why is the text "New Paragraph" not visible in the output? It should appear additionally next to "Old Paragraph".

https://code.sololearn.com/WrTAum0wyqr9/?ref=app

8th Feb 2022, 10:35 AM
CodeX
CodeX - avatar
3 Respostas
+ 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";
8th Feb 2022, 10:46 AM
Shaurya Kushwaha
+ 2
getElementsByClassName in this Element wont work because getElementByClassName is nothing is JavaScript
8th Feb 2022, 11:07 AM
Shaurya Kushwaha
0
Thank you that works! But if I write Element instead of Elements, it should work then without [0] isnt it? Because it doesnt
8th Feb 2022, 10:55 AM
CodeX
CodeX - avatar