frequently ask ? : 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?

14 of 15 people (93%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How can I change the content of a link?

Mar 13th, 2001 07:02
Martin Honnen,


IE4+ and NN6 allow that by setting the 
  innerHTML
property of the link element. It works however more reliably in NN6 to 
use DOM methods:
<HTML>
<HEAD>
<SCRIPT>
function setLinkContent (link, content) {
  if (document.all)
    link.innerText = content;
  else if (document.getElementById)
    link.firstChild.nodeValue = content;
}
</SCRIPT>
</HEAD>
<BODY>
<A HREF="http://JavaScript.FAQTs.com"
   ONMOUSEOVER="setLinkContent(this, 'JavaScript.FAQTs ...');"
   ONMOUSEOUT="setLinkContent(this, 'JavaScript.FAQTs');"
>JavaScript.FAQTs</A>
</BODY>
</HTML>