Next Adjacent Selector ("prev + next")

Selects all next elements matching "next" that are immediately preceded by a sibling "prev".

.next adjacent(prev, next)

prev SelectorAny valid selector.
next SelectorA selector to match the element that is next to the first selector.

One important point to consider with both the next adjacent sibling selector (prev + next) and the general sibling selector (prev ~ siblings) is that the elements on either side of the combinator must share the same parent.

Finds all inputs that are next to a label.

  <label for="name">Name:</label>
  <input name="name" id="name" />
    <label for="newsletter">Newsletter:</label>
    <input name="newsletter" id="newsletter" />
<input name="none" />
$("label + input").css("color", "blue").val("Labeled!");

Looking for a Web Developer?


Hi! I'm Basti, author of this site. If you are looking for a web developer with 15+ years of experience, holla at me!

Be it the good 'ol jQuery, vanilla JS or modern frameworks like Vue and Svelte, front- or backend, I can help you.

Just write me at :)