Have I missed something? All you should need to use is:
document.getElementById("....").setAttribute();
There's a set of such Attribute manipulation functions.
Use them while you still have the object used/returned when create the new element.
In which case, for object 'newObj', you'd use something like:
newObj.setAttribute('id', 'newId_1');