Brian Barthold
Brian Barthold

Reputation: 1623

select last child of element that does not have a certain class

I am try to select the last element of a child that does not have a certain class. I have setup a js fiddle.

<aside class="col2">
    <div class="infobox teal"></div>
    <div class="infobox mediumbrown"></div>
    <div class="quotebox"></div>
    <div class="quotebox"></div>
</aside>  

I have tried:

$("aside.col2 div:last").not(".quotebox").addClass("last-round");

Any thoughts?

Upvotes: 0

Views: 2224

Answers (4)

ecruz
ecruz

Reputation: 783

$("aside.col2 div").not('.quotebox').last();

Upvotes: 0

sachleen
sachleen

Reputation: 31131

$("aside.col2 :not(.quotebox)").last().addClass("last-round");

Select all of the ones that don't have the class, THEN get the last one.

Upvotes: 0

pkurek
pkurek

Reputation: 606

$("aside.col2 div:last:not(.infobox)")

Upvotes: 0

James Montagne
James Montagne

Reputation: 78630

You have to do the not prior to the last:

$("aside.col2 div:not('.quotebox'):last")

http://jsfiddle.net/VATaj/1/

Upvotes: 17

Related Questions