How to modify an attribute contained within a string

How to modify an attribute contained within a string

Hi, I'm receiving html into a variable from an external source and I'm trying to modify the id of one of the inputs within the html but when I change it, the original html isn't getting updated. I've tried a few different ways but so far none have been successful.

an example of what I'm trying to do is :

        var sTemp = "<div><input type='hidden' name='test' id='test' /></div>";
       
        $("#test", sTemp).attr("id","newid");
 
after changing the attribute, sTemp still contains the original code

Any help would be appreciated