Next Adjacent Selector ("prev + next")
Selects all next elements matching "next" that are immediately preceded by a sibling "prev".
.next adjacent(prev, next)
prev
| Selector | Any valid selector. |
next
| Selector | 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.
Finds all inputs that are next to a label.
JS
<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" />
HTML
$("label + input").css("color", "blue").val("Labeled!");
DEMO