PDA

View Full Version : ?? about href w/ onClick to a function


BDT
03-21-2003, 03:45 PM
I'm pretty new at this and want to get a bit more information. I am using an image as a hot spot to click on to call a function. I used some syntax I found elsewhere and want to make sure that I am on track.

<a href="#" onClick="move(3);">

This seems to do what I want, but I have never used the # unless it was used to link to an area in the current page.

Can someone shed a bit of light on this for me or at least confirm that this is the appropriate way to use an image to call a function.

thanks, BDT

boywonder
03-21-2003, 03:55 PM
# represents a link to the top of the current page.

It doesn't matter what you have in the href, assuming you don't want the click to follow the href, just add return false to your onclick

<a href="#" onClick="move(3); return false;">


hope that helps

liorean
03-21-2003, 09:45 PM
No - # refers to a named anchor (or nowadays, any element with an id) with the value of the name/id attribute set to "".

If this doesn't exist, it's just interpreted as the top of the page for most browsers. Some browsers just interpret it as a reload of the current page at the current position, though.

brothercake
03-21-2003, 10:00 PM
It's not really a good idea to do that though, because it's confusing - if you don't have javascript in your browser then you see something that looks like a link, but it doesn't do anything. So either:

- add a real href so that the link goes somewhere; or if this is not appropriate

- don't use a link at all; use the onclick attribute of a different element