How ToJavaScriptMake Web StoriesQuiz GeneratorFAQ Schema GeneratorTable Maker3schools TranslateMore Tools..
Apu
Apu 11/19/2022

Select all child elements except the first

Today our problem is we want to select all child elements except the first one using JavaScript. For example, we have the following code.

<ol>
  <li>Home</li>
  <li>About</li>
  <li>Contact</li>
</ol>

Now, what we have to do is we have to select all li elements and add a class name child to both of them except the first li element. Like the following example.

Example : add class to li elements except the first. #
<ol>
  <li>Home</li>
  <li class="child">About</li>
  <li class="child">Contact</li>
</ol>

We can use the :not() and :first-child selectors. E.g.

document.querySelectorAll("li:not(:first-child)");
Share

Select all child elements except the first

0
Today our problem is we want to select all child elements except the first one using Java…
asked
0 answers

Write an Answer

Related Posts
Write an answer
back