View Full Version : A Link that Does Nothing

08-06-2003, 04:23 PM
In the Weekly Newsletter for July 28, 2003 the following was advice was given.

Sometimes a person needs a link that does nothing when clicked.

For example, image rollovers require a link in order to change
the image. Suppose you only want to change the image when the
mouse moves over the link but don't want a click on the link
to send the browser to another page.

Here is what to do.

In the HEAD section of your web page, put:

<script type="text/javascript" language="JavaScript">
function nothing(){}
// -->

In your "do nothing" links you use the attribute:


For example:

<a href="javascript:nothing()"
onmouseover="ChangeImage(); return true">
<img SRC="../images.jpg" border="0"></a>

This seems like the long way to do it. When I want a link that does nothing I simply do the following.

<a href="javascript:;" MY MOUSEOVER ACTION>MY LINK OR IMAGE</a>

It seems to work on the browsers I have checked it out on. Anyone else have any methods or see anything wrong with mine?[/code]

08-19-2003, 01:45 AM
Another way is....

<a href="#" onmouseover="ChangeImage(); return true">content</a>

08-19-2003, 08:21 AM
The only diffrence between Armadillo's code and mine is the way in which the link will react. Using "#" will cause the page to "jump" back to the top. The method I described will keep the page from "jumping"

There are always so many ways to do the same thing when it comes to codeing a page. It is one of the things I find intrigueing about the whole process. :D

09-02-2003, 05:44 PM
I like wildjokerdesign method better, because it's shorter, but in defence of this other way you can also do:

<A HREF="#" onclick="whatever();return(false);"; onmouseover="......

The other advantage with wildjokerdesign method is that it doesn't matter if the browser uses javascript. I think it's becoming less and less a concern, but I suppose better safe than sorry. :-)