views:

135

answers:

3

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!

+7  A: 

how about this:

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

not sure if it'll work for something like:

<td class="">
Ty W
Hm. Easier than mine. ;) +1
Tomalak
+1: great to know that :)
Sarfraz
This seems to work really well too! Good info.
brandonjp
A: 

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

$("td").filter( function() {return this.className=='';} )
Tomalak
@Tomalak: this isn't just a sympathy note :) I had actually forgotten about the '==' which ended up helping me achieve something else on this current project. so...Kudos!
brandonjp
+11  A: 

You can use an attribute selector with a blank value:

$('[class=]')
Jimmy Cuadra
Arrgghh... I was so close! Kept trying $('td[class=" "]') and other things to select nothing. Your answer was perfect. Thanks!
brandonjp
something about that unbalanced equals sign just seems to strike a nerve with me ;) I'd agree this is the best answer, however.
Ty W