Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67527

Select child when multiple parents with same class - Javascript

$
0
0

I would like to know you if it is possible with pure Javascript to select the child of every parent with the same class. For example:

<div class="parent">
    <a href="#" rel="category tag">Category1</a>
</div>
<div class="parent">
    <a href="#" rel="category tag">Category2</a>
</div>
<div class="parent">
    <a href="#" rel="category tag">Category1</a>
</div>
<div class="parent">
    <a href="#" rel="category tag">Category2</a>
</div>

EDIT:

In this case, I need to select the element of all the and change the background color based on the category: if the category is "Category1" background should be blue, if the category is "Category2" should be red and so on...

Thank you very much.


Viewing all articles
Browse latest Browse all 67527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>