Javascript examples for DOM:Element setAttribute
Element setAttribute() Method - Add a href attribute with a value of "java2s.com" 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() {//from ww w. j av a 2 s . co m document.getElementById("myAnchor").setAttribute("href", "http://www.java2s.com"); } </script> </body> </html>