Next Adjacent Selector ("prev + next")

next adjacent ( prev, next ) version added: 1.0

  • prev
    Type: Selector
    Any valid selector.
  • next
    Type: Selector
    A selector to match the element that is next to the first selector.

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

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.

Examples:

Example: Finds all inputs that are next to a label.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>css demo</title>

  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
  

<form>
  <label for="name">Name:</label>
  <input name="name" id="name">
  <fieldset>
    <label for="newsletter">Newsletter:</label>
    <input name="newsletter" id="newsletter">
  </fieldset>
</form>
<input name="none">

<script>

$( "label + input" ).css( "color", "blue" ).val( "Labeled!" );

</script>

  
</body>
</html>

Demo: