DB a écrit :
I'm just getting into DHTML, and there's one thing I'm getting stuck on
in my current project. I'm building a list of destinations to display in
a window. Each one is in its own separate div. But I can't seem to
figure out how to add a link to those div's on the fly in my script. Is
there a way to do that in JavaScript?
function addLink(divId,link) {
// search, get text inside the div of id div
var txt = document.getElementById(divId);
while(txt.nodeType != 3) txt = txt.firstChild;
// new link tag
var L = document.createElement('A');
// new link href
L.href = link;
// insertion text to new link (precedent text catched)
L.innerHTML = txt.nodeValue;
// place of new link in document body
var target = txt.parentNode;
// delete old text
target.innerHTML = ''
// insertion
target.appendChild(L);
}
</script>
<div id="e1"><p>essai 1</p></div>
<div id="e2"><p>essai 2</p></div>
<div id="e3"><p>essai 3</p></div>
<p><a href="#"
onclick="addLink('e2','page2.htm');return false;">
page 2</a></p>
--
ASM