Use $('a[class]') , this will select all elements that have a class attribute. As I said in my comment, checking for an empty value may not work if the element does not have a class attribute.
Update: As @Sidnicious pointed out , the documentation says that this selector will also select those elements that do not have this attribute. If it was not in version 1.6, then it was actually a mistake in this version, or they changed the description. without mentioning it.
Of course, if you really have an empty class attribute, i.e. <a class=""> , this will not work.
Demo
Update 2: As @lonesomeday mentions in his comment, $('a[class][class!=""]') Works the way you planned with $(a[class!=""]) .
As already mentioned, you can change to on in jQuery 1.7, which unifies event handling methods, but it will not solve your specific problem.
source share