jQuery OR Selector?

Suan picture Suan · Feb 15, 2010 · Viewed 227.6k times · Source

I am wondering if there is a way to have "OR" logic in jQuery selectors. For example, I know an element is either a descendant of an element with class classA or classB, and I want to do something like elem.parents('.classA or .classB'). Does jQuery provide such functionality?

Answer

Daniel A. White picture Daniel A. White · Feb 15, 2010

Use a comma.

'.classA, .classB'

You may choose to omit the space.