How do I tell links apart in JavaScript (the DOM)

M

mike

If I'm looping through the links collection in the DOM in JavaScript how
can I tell the difference between an Image type link and a text url?

I've been looking at document.links.href and document.links,hostname

are there other properties to look at or am I going to have to parse the
link?

thanks
mike
 
L

Lee

mike said:
If I'm looping through the links collection in the DOM in JavaScript how
can I tell the difference between an Image type link and a text url?

I've been looking at document.links.href and document.links,hostname

are there other properties to look at or am I going to have to parse the
link?


You should learn the correct terminology, so you can
ask whatever it is that you want to know.

What do you consider to be an "Image type link"?
I'm guessing that a "text url" is a link containing text,
as in:
<a href="whatever">this is text</a>
but an "Image type link" could be any of:
<a href="whatever"><img src="something.gif"></a>
<input type="image" src="something.gif">
<img src="something.gif" onclick="location='whatever'">
and probably a few more.
 
D

David Dorward

mike said:
If I'm looping through the links collection in the DOM in JavaScript how
can I tell the difference between an Image type link and a text url?

I've been looking at document.links.href and
document.links,hostname


A link to an image/webpage? You can only guess based on the file extension
(or lack off) (or you might be able to achieve something with HTTPRequest,
but that's beyond my current knowledge and I've no inclination to research
it myself right now).

Or a link where the content of the element is an image and/or text
(remember, it could contain both)? In this case you would need to examine
the child nodes of the element. (Check the DOM 1 specification for the
ECMAScript bindings - http://w3.org/DOM/ )
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top