0

getElementsByClassName()[ ]

if we write "getElementsByClassName()[ 1]";we select only second element but if I want to select all elements what must I write ?

1st Jun 2017, 9:10 PM
Serhat Merak
Serhat Merak - avatar
5 ответов
+ 2
document.getElementsByClassName("example") is the pointer of the Node. To access or update all the class elements, you still need to iterate the arrays, eg. var items = document.getElementsByClassName("item") Array.prototype.forEach.call(items, (el,i)=>{el.innerText = "Item "+ i})
2nd Jun 2017, 1:53 AM
Calviղ
Calviղ - avatar
+ 1
just use it without specifying any index between square brackets: document.getElementsByClassName("example");
1st Jun 2017, 9:31 PM
Hsn
Hsn - avatar
+ 1
😑 Thank you 😂😂
1st Jun 2017, 9:32 PM
Serhat Merak
Serhat Merak - avatar
+ 1
welcome 😃
1st Jun 2017, 9:41 PM
Hsn
Hsn - avatar
0
thank you Calvin ☺
2nd Jun 2017, 4:05 AM
Serhat Merak
Serhat Merak - avatar