The :selected selector is used to select option elements those are pre-selected.
Note: To retrieve only the check-boxes or radio buttons, use the :checked selector.
Below examples illustrate the :selected selector in jQuery:
Example 1: This example use CSS property to all pre-selected elements. The background-color of pre-selected element is red, which is changed by :selected selector.
Example 2:This example is similar to previous-one.
- How to reset selected value to default using jQuery ?
- How to get all selected checkboxes in an array using jQuery ?
- How to know which radio button is selected using jQuery?
- How to get selected text from a drop-down list using jQuery?
- How to change selected value of a drop-down list using jQuery?
- How to show contents of selected row of a table in Bootstrap model using jQuery ?
- jQuery | :gt() Selector
- jQuery | :has() Selector with example
- jQuery | * Selector
- jQuery | :contains() Selector
- jQuery | :first Selector
- jQuery | :even Selector
- jQuery | :lt() Selector
- jQuery | #id Selector
- jQuery | :not() Selector
- jQuery | :last Selector
- jQuery | :odd Selector
- Not class selector in jQuery
- jQuery | :lang() Selector
- jQuery | :button Selector
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.