faqts : Computers : Programming : Languages : JavaScript : Event handling

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

7 of 7 people (100%) answered Yes
Recently 4 of 4 people (100%) answered Yes

Entry

How can I access a link href through the links name (anchor) ?

May 30th, 2001 02:44
Spiff Spaceman, sharon,


I know what you mean: if you give a link a name, it is listed in the 
anchors-array as well as in the links-array.But when you call it by name 
you got the anchor, not the link, and this anchor has no href.
I found a workaround:
function showURL(linkName)
{
for(i=0;i<document.links.length;i++)
{if(document.links[i].name==linkName){alert(document.links[i].href)}}
}
You loop through the links-array to find the one with the asked name, so 
you get the index of the link and can ask for href.
Hope it helps.