0

I'm using jQuery to update the value of a text input and, while reading the value back in the same way shows that the .val() is updated, dumping the .html() doesn't reflect the change. A coworker has offered a work around, but I'm not sure why the original doesn't work.

var new_form_resp = $('<div><input value="OLD" type="text"></div>');
new_form_resp.find("input").val("NEW")
// new_form_resp.find("input").attr("value", "NEW") does work

console.log(new_form_resp.html()); // doesn't have the value
console.log(new_form_resp.find("input").val()); // but it does have the value set...

https://jsfiddle.net/1pzt71z6/

The answer seems to be here: https://stackoverflow.com/a/11873770/3208419

Community
  • 1
  • 1
Alex Riina
  • 801
  • 7
  • 11

0 Answers0