Different ways to get selected text from drop-down list:
<script>
$(document).ready(function()
{
$("#cars").change(function(){
alert($("#cars option:selected").text());
alert($("#cars :selected").text());
alert($("#cars").children(":selected").text());
alert($("#cars").find(":selected").text());
});
});
</script>
Working Example
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script>
$(document).ready(function()
{
$("#cars").change(function(){
alert($("#cars option:selected").text());
alert($("#cars :selected").text());
alert($("#cars").children(":selected").text());
alert($("#cars").find(":selected").text());
});
});
</script>
</head>
<body>
<select name="cars" id="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
</body>
</html>
Most Helpful This Week
ES6 method of declaration multiple variables in one line
Write a function that splits an array into groups the length of size and returns them as a two-dimensional array
Using jQuery add new table row on click
How to change the height of Textarea on click?
What's the difference between let and var?
How to define Global Variable in JavaScript?