jquery select first option code example
Example 1: jquery get selected option value
var selectedOptionText = $('#mySelectID').find(":selected").text();
var selectedOptionVal = $('#mySelectID').find(":selected").val();
Example 2: jquery add option to select
$('#selectID').append($('<option>', {
value: 1,
text: 'Option Text'
}));
Example 3: get text of selected option jquery
$('#id').children(':selected').text();
Example 4: select first option in dropdown jquery
myElement.find('option:eq(0)').prop('selected', true);
Example 5: how to select the first div in jQuery
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>first demo</title>
<style>
td {
color: blue;
font-weight: bold;
}
</style>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
<table>
<tr><td>Row 1</td></tr>
<tr><td>Row 2</td></tr>
<tr><td>Row 3</td></tr>
</table>
<script>
$( "tr:third" ).css( "font-style", "italic" );
</script>
</body>
</html>