To add/update an attribute to an HTML element using JavaScript, we set the attributes property.
For instance, we write
const e = document.createElement("div");
e.attributes["id"] = "div1";
to create a div with createElement.
Then we set its id attribute by setting e.attributes["id"] to 'div1‘.