View Full Version : <img /> element nodes sometimes counted as child nodes, sometimes not

12-15-2004, 07:56 PM

I've posted about this before, but received no help. I've read around, asked others, and still find myself stumped, so I'm trying here again. Maybe my savior didn't see the thread before... ;)

I'm finishing off a function that will find <blockquote /> and <q /> elements with the cite attribute defined, and use that URI to construct a link to the quotation source. The blockquote section is working beautifully.

For quotes, I want to use the existing quote text and basically turn that into the link. To do so, I am looping over the child nodes of a <q />, saving those text values into a temporary container that is then appended to the new <a /> which is in turn appended to the <q />.

The problem is with <img /> elements for some reason. As you can see on the test page, if there is a mix of text nodes and <img /> element nodes, my script fails to grab the alt attribute of the <img />. Through some alerting, I've determined that in that instance, the script sees the proper amount of nodes, but just ignores the <img /> for some reason. If there quote contains nothing more than an <img />, the script works as intended.

12-15-2004, 07:59 PM
Have you tried using cloneNode? Be much simpler..

12-15-2004, 08:00 PM
I dunno. Not really familiar with it. I'll heed you statement-as-question and look into it, though. Thanks.

12-15-2004, 08:27 PM
That is indeed a much smarter approach, however I am still getting the same result in the case of a quote containing text and images. The only improvement is that now the case where the quote contains only the image is actually copying the image and not just the text.