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)");
save
listen
AI Answer
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
Apu
0 answers
2915
Today our problem is we want to select all child elements except the first one using Java…
Answer Link
answered
Apu