how to set id in JS code example Example: javascript change element id var element = document.getElementById("oldID"); element.id = "newID";