Find prev() tags with several selectors

javascript, jquery, jquery-selectors, xpath

Solution

jQuery(function($) {
  $('.selector2').prevAll('li.selector, li:not([class])');
});

DEMO

Adding in important comment from @pimvdb

This is correct, but be careful - something like `.addClass("foo").removeClass("foo")` leaves the class attribute behind, although you (might) expect it to be in it's initial state. So it's not quite the same as `[class='']`.

Problem

Let's face this situation: ``` <ul> <li>data</li> <li class="selector">data2</li> <li class="selector2">data3</li> </ul> ``` What i'm trying to do is match `li`s that either have `selector` class or have class attribute `undefined`, something like this: ``` jQuery(function($) { $('.selector2').prevAll('li.selector OR li[class==""]'); }); ``` So if I'm running `prevAll()` on the `.selector2`, it should return 2 list items. If i run it on `.selector`, it should return the first list item. So is there a way to replace that OR ... ? PS: xpath may work for me too as i'm developing for modern browsers

Original source