jQuery Get Selected Option Text onchange

In this tutorial we will see how to Get Selected Option Text onchange with jQuery. The jQuery text() method and change() method can be used to get the text of the selected option when the option is changed.

jQuery text() Method

jQuery text() Method is used to set or get the text content of the selected HTML elements.

In this example text() Method is used to read the text of the selected option of the select tag.

jQuery change() Method

jQuery change() Method triggers the change event or attaches the function with the change event. Thus function will be executed when change event occurs.

In this example change() Method will execute the function as soon as the option of select tag is changed and new option is selected.

HTML Code

HTML Code is given below, in this code we have a select tag with three options. Each option has it's own unique text.

<select name="lang" id="lang">
 <option value="html">HTML</option>    
 <option value="css">CSS</option>    
 <option value="jquery">jQuery</option>    
</select>

JQuery Code

JQuery Code is given below, In this code the text of selected option is read on change event. This text is read using id of select tag and the :selected Selector.

:selected Selector only targets the option which is selected.

Take a look at the code given below.

<script>
$(document).ready(function(){
    $('#lang').change(function(){
       var text= $("#lang option:selected").text();
       alert(text); 
    });
});
</script>

Demo

Video Tutorial

Watch video tutorial on How To Get Selected Option Text onchange using jQuery.

Check radio button Dynamically with jQuery Change Background Color on hover with jQuery Hide and Show div using jQuery Get value of input element with jQuery Remove last child of parent element with jQuery Add li tag to the end of list jQuery Delete first row of Table with jQuery Delete last row of Table with jQuery Add first list item using jQuery jQuery Get id of Button jQuery toggle show hide on click Disable Button after Click with jQuery Get Button Text with jQuery jQuery Dynamic li Click Event How To Remove all Spaces in String with jQuery Get Selected file name in jQuery Remove Last Option of Select tag with jQuery Remove First Option from Select tag in jQuery jQuery Capitalize First Letter of String jQuery Check input value length jQuery Count all elements with same Class jQuery Get Checked Radio Button Value By Class jQuery Highlight Text in Div Get Checked Radio Button Value By Name in jQuery Get Checked Radio Button Value By id jQuery