0
getElementsByClassName()[ ]
if we write "getElementsByClassName()[ 1]";we select only second element but if I want to select all elements what must I write ?
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})
+ 1
just use it without specifying any index between square brackets:
document.getElementsByClassName("example");
+ 1
😑 Thank you 😂😂
+ 1
welcome 😃
0
thank you Calvin ☺