Source Code:
(back to article)
Submit
Result:
Report an issue
<body> <div id="firstID"></div> <div>new id is: <span id="result"></span></div> </body> <script> const div = document.getElementById("firstID"); const result = document.getElementById("result"); div.setAttribute("id", "newDiv"); result.innerHTML = div.id; </script>