Home >>jQuery Tutorial >jQuery selected Selector

jQuery selected Selector

jQuery selected Selector

jQuery selected selector in jQuery is used to selects option elements that are pre-selected.

Syntax:
$(":selected")
Here is an Example of jQuery :selected Selector

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(":selected").css("background-color", "lightgreen");
});
</script>
</head>
<body>
<form action="">
Name: <input type="text" name="user"><br>
Numbers:
<select>
<option>one</option>
<option selected="selected">Two</option>
<option>Three</option>
<option>Four</option>
</select>
</form>
</body>
</html>

Output:
Name:
Numbers:

No Sidebar ads