What is important to realize is that there are empty class attributes as well as elements without a class attribute, but they require different tests to select.
There are a number of tests that all do different things. Here is our HTML for our tests:
<div class="">Empty Class Attribute </div>
<div class="column">Full Class Attribute </div>
<div>No Class Attribute </div>
Now, lets run our tests (The first part is simply a string that helps us know what was just called in the alert, otherwise it is meaningless):
$(document).ready(function(e){
// Outputs "Empty Class Attribute Full Class Attribute"
alert( "div[class] : " + $('div[class]').text() );
// Outputs "Full Class Attribute"
alert( "div[class!=''] : " + $('div[class!=""]').text() );
// Outputs "Empty Class Attribute"
alert( "div[class=''] : " + $('div[class=""]').text() );
// Outputs "No class Attribute"
alert( "div:not([class]) : " + $('div:not([class])').text() );
});
You can view this code in your browser by visiting here: http://jsbin.com/ijupu
Now, armed with this knowledge, if you wanted to select every div
element on the page with either a blank attribute and no attribute, use the following selector:
$("div[class=''], div:not([class])");