Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want a live change event in input text element

I want to handle change event in a text input field. but the event is triggered when the mouse loses focus on element.I want as-type-in change event triggered. what should i do for a live event in jQuery?

I've used :

jQuery('#element').on('change',function(){
//do the stuff
});
like image 339
Ramin Omrani Avatar asked Nov 29 '22 00:11

Ramin Omrani


2 Answers

you can use keyup() event:

$('#someInput').keyup(function() {
    // Your code here
});

there is also an input event:

$('#someInput').on('input', function() { 
    // Your code here
});

as frnhr pointed out, it's better to use input event because: "input will handle any change - e.g. if you paste something in the field, input will trigger but keyup wont."

like image 148
Nasser Torabzade Avatar answered Dec 09 '22 10:12

Nasser Torabzade


You should use keyUp()

$( "#target" ).keyup(function() {
  alert( "Handler for .keyup() called." );
});
like image 20
napolux Avatar answered Dec 09 '22 11:12

napolux