0

I want to select the immediately preceding sibling of an element using jQuery.

I am aware of jQuery's .prev() selector but I was wondering if there is an equivalent to the Next Adjacent Selector (prev + next) - essentially a Previous Adjacent Selector (current + prev) or something like it?

Luke
  • 3,774
  • 29
  • 35

1 Answers1

0

Short answer: no.

This works though:

<p>Hello world!</p> <!-- gets selected class -->
<p id="selector">Hello world!</p>
<p>Hello world!</p>

$('#selector').prev().addClass('selected');
Community
  • 1
  • 1
scrowler
  • 23,965
  • 9
  • 60
  • 90