Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-06-2005, 05:09 PM   PM User | #1
andyf
New to the CF scene

 
Join Date: Jul 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
andyf is an unknown quantity at this point
Link object referencing associated Image object

In accessing links from the document.links[] collection, which yields Link objects, I am attempting to determine whether the link is a text based link or an image link. The first case is fairly easy as the text property of the Link object won't be empty. However, the second case of being an image link comes with the issue of relating to the image.

Is there a native method to correlate a Link object with the Image object?
andyf is offline   Reply With Quote
Old 07-06-2005, 10:31 PM   PM User | #2
martin_narg
Regular Coder

 
martin_narg's Avatar
 
Join Date: Jul 2002
Location: Chamonix, France
Posts: 600
Thanks: 1
Thanked 3 Times in 3 Posts
martin_narg is an unknown quantity at this point
It's kludgy but it works.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script>
function linkTypes() {
	for( var i=0; i<document.links.length; i++ ) {
		alert( (document.links[i].firstChild.src) ? "image" : "string" );
	}
}
</script>
</head>

<body onload="linkTypes();">
<a href="http://www.codingforums.com"><img src="logo.gif" border="0"></a>
<br><br>
<a href="http://www.codingforums.com/showthread.php?t=62886">This is the second link</a>
</body>
</html>
m_n
__________________
"Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
-Tommy Cooper
martin_narg is offline   Reply With Quote
Old 07-07-2005, 05:00 AM   PM User | #3
Harry Armadillo
Regular Coder

 
Join Date: Feb 2005
Posts: 400
Thanks: 0
Thanked 0 Times in 0 Posts
Harry Armadillo is on a distinguished road
I'd be more comfortable with

document.links[i].getElementsByTagName('img').length

as the test for image children. If you're into pretty, indented source then an image link could easily have a white-space node as the link's first child.

Ideally you should look at/for both images and text, so as to spot the popular "icon and text" style of links.
Harry Armadillo is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:29 AM.


Advertisement
Log in to turn off these ads.