Javascript examples for DOM:Element id
Element id Property - Change the id of an element:
<!DOCTYPE html> <html> <body> <p><a id="myAnchor" href="https://www.java2s.com/">java2s.com</a></p> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/* www. j av a 2 s .com*/ document.getElementById("myAnchor").id = "newid"; document.getElementById("demo").innerHTML = "id changed from 'myAnchor' to 'newid'."; } </script> </body> </html>