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.
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<form>
<label>Name:</label>
<input name="name" />
<fieldset>
<label>Newsletter:</label>
<input name="newsletter" />
</fieldset>
</form>
<input name="none" />
<script>$("label + input").css("color", "blue").val("Labeled!")</script>
</body>
</html>