R
R
RushV2021-07-13 16:27:12
JavaScript
RushV, 2021-07-13 16:27:12

How to assign a class to all links in a block except the first one?

There is the following markup:

<div class="col" id="lic-1">
  <a href="#"></a>
  <a href="#"></a>
  <a href="#"></a>
</div>
<div class="col" id="lic-2">
  <a href="#"></a>
  <a href="#"></a>
</div>

It is necessary to add the "d-none" class to all links inside the #lic-1 and #lic-2 blocks, except for the first ones. How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-07-13
@RushV

document.querySelectorAll('.col').forEach(n => {
  n.querySelectorAll('a').forEach((m, i) => m.classList.toggle('d-none', !!i));
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question