When you search for .latasDeRefri
, is bringing only the element that has the class "latasDeRefri", which in this case is the ul
.
If you want all the li
inside it, just include this in the selector:
let latasPepsi = document.querySelectorAll(".latasDeRefri li");
// aqui ^^
for (const li of latasPepsi)
console.log(li);
<ul class="latasDeRefri">
<li>pepsi 1</li>
<li>pepsi 2</li>
<li>pepsi 3</li>
</ul>
Another alternative is to search for li
from the ul
:
// busca o primeiro ul com a classe latasDeRefri
let ul = document.querySelector(".latasDeRefri");
// busca os "li" dentro do ul
for (const li of ul.querySelectorAll('li'))
console.log(li);
<ul class="latasDeRefri">
<li>pepsi 1</li>
<li>pepsi 2</li>
<li>pepsi 3</li>
</ul>
<ul>
<li>outro</li>
</ul>
Note that I have now searched for "li" from ul
found (and not from the document
). So he only seeks what’s inside the ul
(if I searched the document
, he would also find the <li>outro</li>
).
Read to documentation for more information on selectors.
Thank you very much, Marcos :)
– Valdenirson PEREIRA