473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

how to close an anchor created with DOM methods

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!

Mar 23 '06 #1
1 1393
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.

Mar 23 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: nam | last post by:
could someone please help me with this bizarre problem - I've created a swf file at the top of my html page. The swf file (using Swish) is simply a menu of 5 links to 5 anchor points on the html...
2
by: Astra | last post by:
Hi everybody Need your help. I have a DB-extracted list of say 5 items per page, which have links on each one that takes you to more detailed info on the 'clicked' particular item. When you...
30
by: Mason A. Clark | last post by:
This seems too simple by I can't find the answer. Must <a name="foo"> be closed with </a> ? Must it have content? W3C says the content cannot be block so what if : <a name="foo"> <h2>Foo...
10
by: Shang Wenbin | last post by:
Hi, When I want to close the current window using window.close() in IE6.0, there will be a confirm box that: The web page you are viewing is trying to close the window. Do you want to close this...
2
by: jh | last post by:
I am trying to create a simple mdi app with a form anchored down the left of the main form. In this "menu button" form I will have various buttons etc. (i.e. similar to lots of websites) However...
2
by: Rob McKenna | last post by:
Greetings, This is my first foray into CSS and indeed my first website in general. My goal is to use a liquid(ish) design, no javascript and no tables for layout positioning. Rather foolishly I...
8
by: maya | last post by:
I have some links.. http://www.francesdelrio.com/linksCSS.html want it so when you hover over link ENTIRE DIV gets gray bg color (not just text (like link Three is now on this page..) but...
3
by: elwilson | last post by:
Hi, I'm new to php and looking for suggestions for the following situation: 1. I created a list of FAQ's that I want to be able to link to to further down the page (where the complete FAQ is...
1
by: shapper | last post by:
Hello, I am applying a style to a anchor tag. This anchor is created by an ASP.NET page and is inside a list item. I know the style is working because I applied it to the anchor in a page that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.