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
  • 4,825
  • 2
  • 30
  • 37

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
  • 24,273
  • 9
  • 60
  • 92