I wrote a simple javascript function that creates a DOM object (in this case a tag ) and I call it in the of my html page and it doesn’t seem to work. Any ideas?
function create_link() {
var link = document.createElement("a");
link.setAttribute('href', 'the_link.html');
link.setAttribute('name', 'click on link');
document.childNodes[0].childNodes[1].appendChild(link);
}
The createElement and setAttribute calls are fine, are you sure
document.childNodes[0].childNodes[1]is defined?To test, you can do:
document.body.appendChild(link);, which should work.