Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select first element that doesn't have a specific class

I want to write a selector that targets the first element that doesn't have a specific class.

<ul>
<li class="someClass">item 1</li>
<li>item 2</li> <-- I want to select this
<li class="someClass">item 3</li>
<li>item 4</li>
</ul>

I know how to select all elements that doesn't have "someClass":

$('li not:(.someClass)').dostuff();

But I don't know how to only select the first element that doesn't have "someClass".

Anyone knows how to do this?

like image 229
timkl Avatar asked Sep 12 '26 01:09

timkl


1 Answers

$('li:not(.someClass):first')

Here's a working demo: http://jsbin.com/arosa

like image 83
Kobi Avatar answered Sep 14 '26 13:09

Kobi