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

How to Select All Child Elements Except the Last One

In this article, we will talk about how to select all child elements except the last one. For example, we have five anchor (a) elements inside the div element as a child.

<div>
  <a href="#">One</a>
  <a href="#">Two</a>
  <a href="#">Three</a>
  <a href="#">Four</a>
  <a href="#">Five</a>
</div>

Now, we want to style all anchor elements except the last one. So, in this case we can use the css :not() pseudo class with the combination of :last-child pseudo class.

:not(:last-child){
 style here
  }

See the following example. Here we add the same style to all anchor elements. But we also set a 2px right border on all anchor elements except the last one. Click the Try it Yourself » button to open the code in our online editor.

Example: Style All Child Elements Except the Last One #
Share

How to Select All Child Elements Except the Last One

1
In this article, we will talk about how to select all child elements except the last one.…
asked
1 answers

1 Answers

Related Posts (More answers below)
  1. I have try to add some hover effect on the buttons.  Look at Here
    Reply Delete
    Share
Write an answer
back