Link to home
Start Free TrialLog in
Avatar of Dean OBrien
Dean OBrienFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Anchor tag - disable HREF - call javascript function

Experts,

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).

Regards
Easynow
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
        <script>
                function fireAlert()
                {
			alert();
                }
  	</script>
 </HEAD>
 <BODY>
        <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> 
 </BODY>
</HTML>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Albert Van Halen
Albert Van Halen
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
and it is nicer to return false from the function (points to VanHalen):


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
 <head>
        <script>
                function fireAlert()
                {
                        alert('Something');
                        return false
                }
        </script>
 </head>
 <body>
        <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> 
 </body>
</html>

Open in new window

Avatar of Dean OBrien

ASKER

Cheers for comments