how to close an anchor created with DOM methods

B

bob bringas

Hi there,

I'm having trouble closing an anchor created with DOM methods. I am
successfuly creating the anchor, and then giving it an img for its
child node, but for some reason, the anchor is not closing and
continues until the next closing </a> tag in the HTML. What I am doing
wrong?

The situation is I have an image on the page. I want to replace it
with a new image and wrap the new image with an anchor for those
browsers that support the necessary DOM methods.

Here is my html:

<div >
<img id="wantithot" src="images/foo.gif" width="600" height="100"
alt="foo" />
</div>

here is my javascript:

if (document.getElementById && document.getElementsByTagName &&
document.createElement && document.getElementById("wantithot")) {
var theImage = document.getElementById("wantithot");
var container = theImage.parentNode;
var a = document.createElement("a");
a.setAttribute("title","foo");
a.onclick = function() {
return someFunction();
}
var img = document.createElement("img");
img.setAttribute("id","hot");
img.setAttribute("src","images/newfoo.gif");
img.setAttribute("width","600");
img.setAttribute("height","100");
img.setAttribute("alt","new foo");
a.appendChild(img);
container.replaceChild(a,wantithot);
}

This is happening in both Firefox 1.04/win and IE 6.028/win.

Any ideas?

thanks!
 
B

bob bringas

ugh! never mind. I should debug more thoroughly before posting next
time. The problem was an unclosed anchor tag above the html in
question. Bugs are almost always dumb mistakes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top