0

Why it's showing undefined?

I want to output the value of all p tags but it's showing undefined!! https://code.sololearn.com/Wr3OQ41hV0w4/?ref=app

13th Feb 2021, 2:26 PM
Technical Code
Technical Code - avatar
7 Réponses
+ 6
Technical Code html tags except form elements (input, textarea) doens't contains attribute value means you can't get using value. Use innerHTML. The getElementsByTagName() method returns a collection of an elements's child elements with the specified tag name. Try this console.log(p[0].innerHTML) https://code.sololearn.com/WGF8l304g4kx/?ref=app
13th Feb 2021, 3:15 PM
A͢J
A͢J - avatar
+ 3
Technical Code Your Code is working properly according to me. But yeah, it is showing undefined that I don't understand too.
13th Feb 2021, 2:41 PM
Ezra Bridger 2207 [INACTIVE]
Ezra Bridger 2207 [INACTIVE] - avatar
+ 2
ODLNT Array is also a collection.
13th Feb 2021, 3:28 PM
A͢J
A͢J - avatar
+ 2
Thank you very much I Am AJ !
13th Feb 2021, 3:32 PM
Technical Code
Technical Code - avatar
+ 1
I Am AJ ! getElementsByTagName, does it return an array or a collection?
13th Feb 2021, 3:27 PM
ODLNT
ODLNT - avatar
+ 1
ODLNT Actually it's a collection of Nodes.
13th Feb 2021, 3:32 PM
A͢J
A͢J - avatar
0
console.log(p[1].value) ?
14th Feb 2021, 7:43 AM
lloyd
lloyd - avatar