Javascript examples for DOM HTML Element:Anchor
You can create an <a> element by using the document.createElement() method:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <script> function myFunction() {/*from ww w . j a v a 2s . com*/ var x = document.createElement("A"); var t = document.createTextNode("Tutorials"); x.setAttribute("href", "https://www.java2s.com"); x.appendChild(t); document.body.appendChild(x); } </script> </body> </html>