faqts : Computers : Programming : Languages : JavaScript : Links

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 8 people (88%) answered Yes
Recently 2 of 3 people (67%) answered Yes

Entry

Why is the text property of alink not available sometimes to a certain link ?

Jun 12th, 2002 06:21
David Blackledge, sharon,


First, let's note that the "text" property is only a property of links 
in Netscape 4.  It's not available in IE or Netscape 6 (I assume... 
because it's not part of the W3C DOM).
In Netscape 4, they got a little weird when it came to dealing with 
links versus anchors.  Since both use the "A" tag, they got a bit 
confused.  If you specify an HREF value, the item is a link.  If you 
specify a NAME value, the item is an anchor.  If you specify BOTH, it 
shows up in BOTH arrays, except only PARTS are in both arrays.
Specifically, an A tag with both an HREF and a NAME has a Link object in 
the links array where the text, x, and y properties are all NULL.  It 
also has an Anchor object in the anchors array which has "stolen" the 
text, x, and y properties and still has its usual "name" property.  
(Link objects in the links array do not ever have a name property).
So, if you specify a "name" property, your text property will be null on 
the link.
Even more maddening is there is NO way to match up the Link object to 
the Anchor object to get all of the data together.  There is no shared 
information, and the links and anchors arrays are independent.  The best 
you could hope for is if you make EVERY link into both a link AND an 
anchor by including a NAME, then the array indices would match up.
David.
http://David.Blackledge.com