Javascript examples for DOM:Element setAttributeNode
Element setAttributeNode() Method - Set the href attribute node of a <a> element:
<!DOCTYPE html> <html> <body> <a id="myAnchor">A Link: go to java2s.com</a> <button onclick="myFunction()">Test</button> <script> function myFunction() {/*from w ww.ja va 2s . c om*/ var anchor = document.getElementById("myAnchor"); var att = document.createAttribute("href"); att.value = "http://www.java2s.com"; anchor.setAttributeNode(att); } </script> </body> </html>