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!
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!