tadam logo
Did you find an error in the text?
Select this with mouse and press
Ctrl + Enter
Xhtml.co.il Check Spelling
Orphus system

prev + next

next adjacent selector

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

jQuery('prev + next')

version added: 1.0
prev
Any valid selector.
next
A 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.

Examples

Finds all inputs that are next to a label.
$("label + input").css("color", "blue").val("Labeled!")
The output of the code above will be:
Full source:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>  
  <script>
  $(document).ready(function(){
$("label + input").css("color", "blue").val("Labeled!")
  });
  </script>  
</head>
<body>
  <form>
    <label>Name:</label>
    <input name="name" />
    <fieldset>
      <label>Newsletter:</label>
      <input name="newsletter" />
    </fieldset>
  </form>
  <input name="none" />
</body>
</html>
Was this information helpful?
   

Comments