Is it possible to select all elements that do not have a CSS class?

advertisements

The W3C Recommendations defines the ability to select any anchor which has a defined class by using A[CLASS]{/*Code*/}, but is there an antecedent?

Can I select all anchors that do NOT have a class?

My instinct is to use A[~CLASS]{/*Code*/}, but that isn't documented, and A[CLASS=]{/*Code*/} selects all anchors which have a class name which is an empty string (for instance, <A CLASS="" HREF="http://example.com/">This anchor has a class, but it's empty.</A>).

Example usage


In this code, I only want classless links to be green.

<HTML>
<HEAD>
<LINK REL="stylesheet" TYPE="text/css" HREF="http://example.com/externalUneditableStyles.CSS" />
<STYLE>
A.deadLink{
color:#FF0000 !important;
}
A{
color:#00FF00;
}

</STYLE>
</HEAD>

<BODY>
<A HREF="http://fakesite.not/" CLASS="deadLink">This link is red, as specified by the CSS above.</A>
<A HREF="http://example.com/">This link is green, as specified by the CSS above.</A>
<A HREF="#/childpage/" CLASS="childLink">This is a link to a child page, and is styled by external uneditable CSS. That CSS doesn't specify a color, so it is green, even though that might not be the intended effect.</A>
</BODY>
</HTML>


Use something like this:

a:not([class]) {
    /*some styling here*/
}

Little demo: little link.