I need to find, via jQuery selectors, all spans in a page that have no class.
Example:
<span class='Cool'>do not found me</span>
<span>me, me, take me please!!!</span>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
:not()and the attribute not selector[att!=val]to filter out elements with a non-emptyclassattribute:jsFiddle preview
Note however that
[att!=val]is a non-standard jQuery selector, which means the selector cannot be used in CSS or withdocument.querySelectorAll(). If you’re like me, and you’re a stickler for following the standards and so want to eschew non-standard jQuery selectors where possible, the following is a direct equivalent:This matches
spanelements that have noclassattribute, andspanelements that do have aclassattribute, but only when the attribute value is empty.In most cases, though, you should be able to get away with just the first portion:
You’ll usually only find empty
classattributes in markup generated by the application that’s responsible for outputting it, or by developers who aren’t paying attention.