$(htmlString).attr("value", "newValue");
But this will return a jQuery object, not a string. You can add it to the DOM.
$(htmlString).attr("value", "newValue").appendTo("body");
EDIT:
You can use the @idor_brad method. This is the best way or
var htmlString = '<input type="text" id="someID" name="someID">'; var $htmlString = $(htmlString); $htmlString.attr("value1", "newValue1"); $htmlString.attr("value2", "newValue2"); $htmlString.attr("value3", "newValue3"); console.log($htmlString.get(0).outerHTML);
or
var htmlString = '<input type="text" id="someID" name="someID">'; var $htmlString = $(htmlString); $htmlString.attr("value1", "newValue1"); $htmlString.attr("value2", "newValue2"); $htmlString.attr("value3", "newValue3"); console.log($("<div>").append($htmlString).html());
Diode source share