ehsan ehsan - 5 months ago 25
jQuery Question

Change event doesn't working when input text change?

This is my code:

<input type="text" id="x">


$(document).ready(function(){
$("#x").onchange(function(){
alert("x");
})
});


But id doesn't work. What is problem?

Answer

Change code like :

html>
    <head>
        <style>
        </style>
    </head>
    <body>
        <input type="text" id="x">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <script>
            $(document).ready(function(){
                $("#x").change(function(){
                    alert("x");
                })
            });
        </script>
     </body>
</html>