How to select the previous element of a given class

Posted by JCN on Stack Overflow See other posts from Stack Overflow or by JCN
Published on 2012-09-06T15:26:42Z Indexed on 2012/09/06 15:38 UTC
Read the original article Hit count: 175

Filed under:
|

I have an UL list :

<ul>
  <li data-sel='foo'></li>
  <li></li>
  <li data-sel='foo'></li>
  <li class='selected'></li>
  <li data-sel='foo'></li>
 </ul>

I can access the first previous element of li.selected who do not have attribute data-sel=foo by using :not selector

var element = $('.selected').prev("li:not([data-sel='foo'])");

But how can i access the first previous element of li.selected who have attribute data-sel=foo ?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery