A
A
Andrey2021-07-05 19:38:54
JavaScript
Andrey, 2021-07-05 19:38:54

How to add a class to all blocks that are displayed after the 3rd block?

How to add a class to all blocks that are displayed after the 3rd block?
for example , after the 3rd block, the green class should be substituted for all the rest

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2021-07-05
@klekovkinandrey

If parent is common:

document
  .querySelectorAll('.service:nth-child(n + 5)')
  .forEach(n => n.classList.add('green'));

Otherwise:
Array
  .from(document.querySelectorAll('.service'))
  .slice(4)
  .forEach(n => n.classList.add('green'));

S
Sergey Sokolov, 2021-07-05
@sergiks

You can simply style:

.container div:nth-child(n + 4){
  border:1px solid green;
  background-color:lightgreen;
}

spoiler

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question