0

I have inputs in my html:

<input type="text" id="1" value="1" name="1">
<input type="text" id="2" value="2" name="2">

And than i use ajax and load put another one input:

<input type="text" id="3" value="3" name="3">

There is javascript file with code:

$('input[type=text]').focusin(function() {
    var Id = this.id;
    someActionWithId(Id);
}).focusout(function(){
    var Id = this.id;
    someActionWithId(Id);
});

Can some one tell me why i cant pick input that is loaded by AJAX. Maybe some one can suggest some solution? Thanks.

1 Answers1

2

You need to bind event for dynamically loaded elements like this :

$(document).on('focusin','input[type=text]',function() {
    var Id = this.id;
    someActionWithId(Id);
});
$(document).on('focusout','input[type=text]',function(){
    var Id = this.id;
    someActionWithId(Id);
});
Bhushan Kawadkar
  • 28,279
  • 5
  • 35
  • 57