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?
change this:
$("#x").onchange
to this:
$("#x").change
There is a .on() listner, so this can also be used:
$("#x").on('change', function(){
alert("x");
})
You have a jQuery object and you have to bind the jQuery methods only. And change event on input[type=text] works when you off the focus out of it.
$.onchange is not a function. You are getting confused between native JavaScript, which allows
<input onchange="doSomething()"/>
and jQuery, which requires
$(selector).on("change",function(){...});
The correct function is $.on(event) where event is a string. In this case you need
$("#x").on("change",function(){..});
keyupinstead ofonchangeevent.onchangeis event of javascript. Change event in jquery is.change