selected selector
Description: Selects all elements that are selected.
-
version added: 1.0jQuery( ":selected" )
The :selected
selector works for <option>
elements. It does not work for checkboxes or radio inputs; use :checked
for them.
Additional Notes:
- Because
:selected
is a jQuery extension and not part of the CSS specification, queries using:selected
cannot take advantage of the performance boost provided by the native DOMquerySelectorAll()
method. To achieve the best performance when using:selected
to select elements, first select the elements using a pure CSS selector, then use.filter(":selected")
.
Example:
Attaches a change event to the select that gets the text for each selected option and writes them in the div. It then triggers the event for the initial text draw.
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
26
27
28
29
30
31
32
33
|
|