Suppose I loaded the field through an AJAX and inserted it into the document via html (), after I changed it, how do I get the new value of this field? When called, its value returns undefined.

function set() { $.ajax({ type: 'GET', url: 'blablabla', success: function(res) { $('#section').html(res); } }); } function get() { var input = document.getElementById('input').value; alert(input); } 

Well, this is the field itself.

 <input type="text" id="input" value="" onchange="get()"> 
  • >> after I changed it in what sense "changed"? Fill in the field value manually or what? - ModaL
  • Yes, filled in the field value manually. - rimlin
  • @rimlin, try to start with the following: >> <input type = "text" id = "input" value = ""> <input type = "button" onclick = "get ()" value = "Get value"> - ModaL
  • undefined still - rimlin
  • @rimlin, try this: var input = $ ('# input'). val (); - ModaL

2 answers 2

Comments off. I will write here.

Try this:

 var input = $('#section').find('#input').val(); 
  • decided the question, thanks - rimlin

Delegate the "onchange" event with .on()

 $('body').on('change', 'input'/*ваш селектор*/, function(){ alert(this.value); }); 

proof