Skip to content
Advertisement

How to select specific elements inside of another specific divs with query selector?

code is like this

<div class="linkPillar">
  <a href="github"><img src="github.png" alt="GitHub"></a>
  <a href="facebook"><img src="fb.png" alt="facebook"></a>
</div>

and i want to select all a’s just inside of linkPillar without giving each of them an id. is there any way to make this, thanks

Advertisement

Answer

You can use the query selector to find the elements:

console.log(document.querySelectorAll('.linkPillar a'));
<div class="linkPillar">
        <a href="github"><img src="github.png" alt="GitHub"></a>
        <a href="facebook"><img src="fb.png" alt="facebook"></a>
</div>
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement