0

http://jsfiddle.net/Lvq08t6d/

CSS:

div p.test:not(:last-child) {
    background: red;
}

I am trying to select all p with class test only except the last one and it's not working.

Fiddle with :last-of-type: http://jsfiddle.net/Lvq08t6d/1/ which didn't work for me.

Si8
  • 9,141
  • 22
  • 109
  • 221

1 Answers1

2

It's not possible with only CSS. Here is a way of using jQuery:

$('.test:not(:last)').css('color', 'red');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
  <p class="test">The first paragraph.</p>
  <p class="test">The second paragraph.</p>
  <p class="test">The third paragraph.</p>
  <p class="test">The fourth paragraph.</p>
  <p class="test"><b>Note:</b> Internet Explorer 8 and earlier versions do not support the :nth-last-child() selector.</p>
  <p>another P here...</p>
</div>
Stickers
  • 75,527
  • 23
  • 147
  • 186