PDA

View Full Version : Anchor Tags: using onclick


w0lf42
05-21-2004, 06:05 PM
I have always wondered what the difference between, in an anchor tag/element, placing the javascript on the href attribute and creating an onclick attribute.

<a href="javascript:functionName();">click me </a>
versus
<a href="#" onclick="functionName();">click me</a>

Please let me know which way is best.

BTW, I am aware of the space between "java" and "script", but it seems as though the forums added it automatically.

Thanks.

agent002
05-21-2004, 06:10 PM
Hi Wolf,
I prefer the onclick method - the href method can have odd consequences, for instance if the function returns something:
function doStuff(){
return false;
}
Using the href method will print "false" on your screen.

w0lf42
05-21-2004, 06:36 PM
Thanks Agent002.

You seem to be very active and helpful.