Helpful Information
 
 
Category: Web Design and HTML
A Link that Does Nothing

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.

(1)
In the HEAD section of your web page, put:

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

(2)
In your "do nothing" links you use the attribute:

href="javascript:nothing()"

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]

Another way is....


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

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

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

SJP










privacy (GDPR)