Javascript examples for DOM:Document createAttribute
Document createAttribute() Method - Create a href attribute, with the value "www.java2s.com", and insert it to an <a> element:
<!DOCTYPE html> <html> <body> <a id="myAnchor">A Link: go to java2s.com</a> <button onclick="myFunction()">Test</button> <script> function myFunction() {/* www . j a va 2s .c o m*/ var anchor = document.getElementById("myAnchor"); var att = document.createAttribute("href"); att.value = "http://www.java2s.com"; anchor.setAttributeNode(att); } </script> </body> </html>