JavaScript in links Mar08 '06

Feedback

# (1 of 2): Josh » joahua.com/blog

1 hour, 45 minutes after the fact. (Wed 08 Mar 2006, 4:29 PM CST)

# (2 of 2): Josh » joahua.com/blog

1 hour, 48 minutes after the fact. (Wed 08 Mar 2006, 4:31 PM CST)

Uhh, it ate my code.

a href="version for people without javascript or search engines" onclick="doStuff(); return false;"

obviously wrapped in lt/gt signs, which I’m not trying again for obvious reasons.

return false; cancels the link’s default action. You can also stick that in the doStuff() function, or whatever. And yeah, onclick doesn’t have to be inline... if you’re feeling really clever you can attach it with DOM methods, etc., but so often that’s just too hard (especially where the code is server-generated anyway, and "markup purity" is a relative term because THAT markup only exists for the duration of page runtime!)

Previous comment Return to entry

RSS feed for comments on this post

Leave feedback

Feedback

Input format: The editor controls below will assist with Markdown syntax.

Status

Sub-status

Your info

Return to entry.

matthom is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago. Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.

Contact Matt

What is the best way to disable a link’s normal activity, on click?

You are at the feedback permalink page for: JavaScript in links

Read more...