Create a link in javascript
I have made a test function for adding links in a submenu for a menu I'm making. The problem is I don't know how to create a HTML link in java script. The function works if I just use it for just inserting text, but obviously not when I using the 5 lines of code to create the link.I you know a nice way of creating links i java script It should be very easy :-)
function submenuTest()
{
var mytable=document.getElementById("mySubmenu");// it's a table
mytablebody = document.createElement("TBODY");
//for(j=0;j<1;j++) {
mycurrent_row=document.createElement("TR");
for(i=0;i<1;i++) {
mycurrent_cell=document.createElement("TD");
//lnk = document.createTextNode("Områdefornyelse");
//-- This does not work, a is my problem
text = "Områdefornyelse";
url = "http://www.google.dk";
tr = document.selection.createRange();
tr.text = '<a href="' + url + '" name="' + text + '">' + tr.text + '</a>';
lnk = document.createLink(tr.text);
//-- The creation of the link is done
mycurrent_cell.appendChild(lnk);
mycurrent_row.appendChild(mycurrent_cell);
}
mytablebody.appendChild(mycurrent_row);
//}
mytable.appendChild(mytablebody);