Introduction:

  • In this article we will explain how to how to get selected value of dropdown after change in jquery or What is change() method in jquery or why use change() method in jquery with example.

  • Description:
  • jQuery change event occurs when the value of an element is changed. It works only on form fields  <input>, <textarea> and <select> elements. The change() method triggers the change event, or attaches a function to run when a change event occurs.

  • Syntax:
  • $(selector).change()  

  • Example of jQuery change() method


Let's take an example to demonstrate jQuery change() Method.

<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script>
        $(document).ready(function () {
            $("select").change(function () {
                $("#languageName").html("You selected: "+$("#language").val());
            });
        });
    </script>
</head>
<body>
    <select id="language" name="language">
        <option selected="selected"></option>
        <option>c Sharp</option>
        <option >Asp.Net</option>
        <option>MVC</option>
        <option>SQL Server</option>
        <option>Java</option>
        <option>Jquery</option>
    </select>
    <div id="languageName" style=" margin-top:10px;"></div>
   
</body>
</html>

Output:

how to use change event in jquery

In above example when we change dropdown selection then call change event.

and get selected value.

 

I hope this article will help to you.

0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like