jQuery get select option text value

Example code for jQuery get select option text value and following points: get select value JavaScript, get select value jquery, jQuery: get the selected option text, How to get the current value of the title attribute in a select, jQuery loop select options, how to get select value from dropdown using jquery, How to Get the Value of Selected Option in a Select Box, DOM – Get selected option text with JavaScript, jquery get select option text and value, JQuery iterate through all option elements in a multiple and jquery for loop select options.

jQuery get selected option text value

Get selected option object using $(‘SELECTOR option:selected’), after this get selected option value and text using text() and val() function.

<select id="myselect1">
<option value="opt1">Option 1</option>
<option selected="selected" value="opt2">Option 2</option>
<option value="opt3">Option 3</option>
</select>

<script>
$(function(){
 var selVal = $('#myselect1 option:selected').val();
 var selText = $('#myselect1 option:selected').text();
 console.log(selVal);
 console.log(selText);
});
</script>

jQuery get selected option value in multiple select

Get selected option objects group using $(‘SELECTOR option:selected’), after this make each loop on group and fetch selected option value using val() function and push it in array for next step process.

<select id="myselect2" multiple="multiple">
<option value="opt1">Option 1</option>
<option selected="selected" value="opt2">Option 2</option>
<option selected="selected" value="opt3">Option 3</option>
</select>

<script>
$(function(){
 var selValArr = [];
 $('#myselect2 option:selected').each(function(){
  selValArr.push($(this).val());
 });
	
 console.log(selValArr);
});
</script>

jQuery get all option text and value

Get select all option objects group using $(‘SELECTOR option’), after this make each loop on group, fetch option value and text using text(), val() function and push it in array for next step process.

<select id="myselect3">
<option value="opt1">Option 1</option>
<option value="opt2">Option 2</option>
<option value="opt3">Option 3</option>
</select>

<script>
$(function(){
 var selValArr = [];
 var selTextArr = [];
 $('#myselect3 option').each(function(){
  selValArr.push($(this).val());
  selTextArr.push($(this).text());
 });
	
 console.log(selValArr);
 console.log(selTextArr);
});
</script>