Примеры для jQuery Смежные селекторы (“prev + next”)


Finds all inputs that are next to a label.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>next adjacent demo</title>
<script src="https://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>

Демонстрация: