Mega Code Archive

 
Categories / JavaScript DHTML / HTML
 

Create a hyper link element and set the id and href attributes

<head> <title></title> </script> </head> <body> <script type = "text/javascript" > var pTag = document.createElement("p"); pTag.setAttribute("id","myP"); document.body.appendChild(pTag); pTag.appendChild(document.createTextNode("This is a paragraph.")); var hyperLinkTag = document.createElement("a"); hyperLinkTag.setAttribute("id","myA"); hyperLinkTag.setAttribute("href","http://www.google.org/"); document.body.appendChild(hyperLinkTag); hyperLinkTag.appendChild(document.createTextNode("Web Site.")); </script> </body>