Search code examples
jqueryjquery-selectors

jQuery OR Selector?


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?


Solution

  • Use a comma.

    '.classA, .classB'
    

    You may choose to omit the space.