By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,628 Members | 1,880 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,628 IT Pros & Developers. It's quick & easy.

appendChild not attaching anchor link as expected

P: 65
I have a simple XMLHttpRequest that grabs a list of messages from my server (I posted a question for a different aspect of this earlier)

I have decided to improve on it a little by adding in things that my message logger does (server-side) to turn things like:
Expand|Select|Wrap|Line Numbers
Expand|Select|Wrap|Line Numbers
into URLs automatically by slapping on
Expand|Select|Wrap|Line Numbers
  1. <a href="" target="_blank"></a>
Expand|Select|Wrap|Line Numbers
is found in a message.

I checked and double-checked the message log, and it is properly parsing the text to include valid HTML. The problem occurs when I receive the text on the client. It iterates through all the child elements of the <content> element of each <message> element, and appends them to a <span> element inside a <p> element that it will be appended to the chat history. It seems to be properly attaching the <a> element including the text inside, but it is not clickable, as if I passed it without the href attribute. Anyone have any insight to this?

Library file:

EDIT: The place in which I am attaching all the elements of the message occur between lines 264 and 274.

If you wish to test the script, just enter a username, and create a room, then enter any URL into the script at:

Also, inspecting the elements using Firebug in Firefox reveals that the href is there, but unless I delete and re-add the element manually, it does not act like a link completely (but it stands out like one).
Dec 6 '08 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 392
I can not follow the code. It looks like you are iterating over an newly declared empty array. The simplest way to see the problem would probably be to show the innerHTML attribute from the created element in an alert call so you can see the actually HTML that is being created.

Expand|Select|Wrap|Line Numbers
  2.     var genHTML = message.innerHTML;
  3.     alert('  HTML CREATED : '+genHTML);
Dec 6 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.