Get dropdown text in jQuery

Sometime we need to get selected text instead of its value of a dropdown, it is very easy to get dropdown text in jQuery. You have to use text() function of jQuery. It will return the text of option which is currently selected in your dropdown.

$(".ddlCountry option:selected").text()

CODE
<!DOCTYPE html>
<html>
<head>
  <title>jQuery With Example</title>
  <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
  <script type="text/javascript">
    $(function () {
      $('.btnClick').click(function () {
        alert($(".ddlCountry option:selected").text());
      });
    });
  </script>
</head>
<body>
  <div>
    <select class="ddlCountry">
      <option value="1">India</option>
      <option value="2">Japan</option>
      <option value="3">England</option>
    </select>
    <br /><br />
    <input type="button" class="btnClick Button" value="Click" />
  </div>
</body>
</html>
DISPLAY


No comments :

Please Give Your Feedback