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

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

P: n/a

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[i].href and document.links[i],hostname

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

thanks
mike
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
mike wrote:

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[i].href and
document.links[i],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/ )
--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 23 '05 #2

P: n/a
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[i].href and document.links[i],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.

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.