I have a variable containing a form with an input box, and I'd like to change the value attribute of said input box using jquery. So far, I'm able to change the value, but it doesn't get changed in the outer html. This' what I've got so far:
$("a").click(function(event) {
var form_content = "<form><input id=\"name\" value=\"Test value\"/></form>";
var test = $('<div />').html(form_content).find('#name').val('New test value').parent();
alert(test.find('#name').val());
alert(test.html());
return false;
});
also available at jsfiddle. The first alert
displays "New test value"
, yet the second alert
doesn't reveal any hint of how this new value is stored - basically it returns the same value as the original variable form_content
.
I've had a look here, but can't understand what I'm doing wrong.
Could anyone please help me connect the dots, and possibly give me a hint of how I can change the html stored in form_content
? (There seems to be plenty of examples of how to do it in plain static html, but that's unfortunately not an option for me.) Thanks!