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?

21 of 27 people (78%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How do I get the text content of a link?

Mar 12th, 2000 04:01
Martin Honnen,


NN4 has a
  text 
property for links (A HREF elements) while IE4+ uses the 
  innerText
property available for all HTML elements.
So
  var link = document.links[linkIndex];
  var text = document.all ? link.innerText : 
             link.text ? link.text : '';
is a cross browser way to access the text content of a link.