brandonjp
brandonjp

Reputation: 3068

jQuery - How to select elements that do NOT have a class?

How do I get elements that do not have any class names?

        <td class="B A">A03<sub>reserved</sub></td>
        <td class="B R">R70</td>
        <td>105</td>
        <td class="M C">L220</td>

Right now I'm doing this $('td').not('.A, .B, .C, .M, .R')

There's gotta be a better way!

Upvotes: 3

Views: 3721

Answers (3)

Jimmy
Jimmy

Reputation: 37081

You can use an attribute selector with a blank value:

$('[class=]')

Upvotes: 12

Tomalak
Tomalak

Reputation: 338148

One way to do it is to use filter():

$("td").filter( function() {return this.className=='';} )

Upvotes: 0

Ty W
Ty W

Reputation: 6814

how about this:

$("td:not([class])")

not sure if it'll work for something like:

<td class="">

Upvotes: 7

Related Questions