Apparently these two functions are similar, which is more performative? Which one should I use? What's the difference between the two?
document.querySelectorAll ()
function funDOM() {
var x = document.querySelectorAll(".example");
var i;
for (i = 0; i < x.length; i++) {
x[i].style.backgroundColor = "red";
}
}
<html>
<body onload="funDOM()">
<div>
Duvidas <span class="example">vermelhas</span>
</div>
<p class="example">vermelho</p>
</body>
</html>
document.getElementsByClassName ()
function funDOM() {
var x = document.getElementsByClassName("example");
var i;
for (i = 0; i < x.length; i++) {
x[i].style.backgroundColor = "red";
}
}
<html>
<body onload="funDOM()">
<div>
Duvidas <span class="example">vermelhas</span>
</div>
<p class="example">vermelho</p>
</body>
</html>
Thank you in advance for your consideration.