Generate the new markup¹ in a
string (ugh!)² and then use the jQuery
attr() method to change the attribute value.
¹ I'd try this with a small hard-coded sample to see if it will even work before going through the trouble of generating real markup.
² You might want to explore a templating framework like Handlebars to help generate markup from a template rather just using string concatenation.