G
GIAM
Hi,
I'm trying to create a dynamic link with javascript. However, I can't
seem to add the link onto the page (at least I assume that is the
problem). Here is the function I use:
function createLink(id)
{
var x = document.getElementById('background');
var newLink = document.createElement('a');
newLink.setAttribute('id',id)
newLink.setAttribute ('href','"javascript:;"');
newLink.setAttribute ('onmousedown', 'toggleDiv(text)');
//alert();
x.appendChild(newLink);
alert(newLink.getAttribute('id'));
alert(newLink.getAttribute('href'));
alert(newLink.getAttribute('onmousedown'));
}
background is just the background div of the page, I also tried
document.body.appendChild but this doesn't work either. I create the
link using a button:
<button onclick="createLink('alink')"> createlink</button>
I also have code to create a dynamic div box which works, using
document.body.appendChild(newdiv).
I'm using IE 7.
Thanks,
GIAM
I'm trying to create a dynamic link with javascript. However, I can't
seem to add the link onto the page (at least I assume that is the
problem). Here is the function I use:
function createLink(id)
{
var x = document.getElementById('background');
var newLink = document.createElement('a');
newLink.setAttribute('id',id)
newLink.setAttribute ('href','"javascript:;"');
newLink.setAttribute ('onmousedown', 'toggleDiv(text)');
//alert();
x.appendChild(newLink);
alert(newLink.getAttribute('id'));
alert(newLink.getAttribute('href'));
alert(newLink.getAttribute('onmousedown'));
}
background is just the background div of the page, I also tried
document.body.appendChild but this doesn't work either. I create the
link using a button:
<button onclick="createLink('alink')"> createlink</button>
I also have code to create a dynamic div box which works, using
document.body.appendChild(newdiv).
I'm using IE 7.
Thanks,
GIAM