Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Check link's validity with JavaScript

Posted on 2008-06-23
Medium Priority
Last Modified: 2008-06-23
<a href="" id="L523136">Link to Example</a>

Using JavaScript at the bottom of my page how can I test if the link is to and the link text is "Link to Example" ?

I want False to be returned if either the link or the link text has been changed.
Question by:hankknight
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 14

Accepted Solution

agriesser earned 2000 total points
ID: 21845005
Below is a function "CheckLink" that should work. Please note the '/' at the end of Firefox at least adds a / to all domains in the href attribute of links, don't know for other browsers.
function CheckLink()
  if((document.links['L523136'].href == "") &&
     (document.links['L523136'].text == "Link to Example"))
    return true;
  return false;

Open in new window

LVL 16

Author Comment

ID: 21849127
Thank you, agriesser.

Your example works on its own but when I tried to integrate it into my app it does not work in IE.

I posted a question about that here:

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question