Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
getElementsByClassName()[ ]
if we write "getElementsByClassName()[ 1]";we select only second element but if I want to select all elements what must I write ?
5 Respostas
+ 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 āŗ