• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 891
  • Last Modified:

Anchor tag - disable HREF - call javascript function


I was pretty sure i knew how to do this, yet it doesnt seem to want to work in firefox, please can you look at the code below and see what im doing wrong...

It still links though to the HREF (on firefox).

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
                function fireAlert()
        <a href="yourlink.com" onclick="fireAlert();return false">test1</a>
        <a href="mylink.com" onclick="fireAlert();return false">test1</a>
        <a href="theirlink.com" onclick="fireAlert();return false">test1</a> 

Open in new window

Dean OBrien
Dean OBrien
1 Solution
Albert Van HalenAnalyst developerCommented:
The statement alert() (with no arguments) fails.
Just alert something (ie alert("Hi there!")) and you will see that it works
Michel PlungjanIT ExpertCommented:
and it is nicer to return false from the function (points to VanHalen):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
                function fireAlert()
                        return false
        <a href="yourlink.com" onclick="return fireAlert()">test1</a>
        <a href="mylink.com" onclick="return fireAlert()">test1</a>
        <a href="theirlink.com" onclick="return fireAlert()">test1</a> 

Open in new window

Dean OBrienAuthor Commented:
Cheers for comments
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now