/    Sign up×
Community /Pin to ProfileBookmark

href="javascript: vs onclick="functionname()"

In my past I’ve been calling Javascript functions more so through the <a href=”javascript function();”>link</a> method than an onclick. However I believe this is w3c uncompliant, and is causing some errors in validation.

What I’ve resorted to right now is doing something like.

<a href=”#” onclick=”function();”>link</a>

The only problem with this is then I’m puting a # in the current address bar, and well I’d rather the URL stay the same.

Any suggestions? If I leave the href=”” then it just redirects to the current page.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KorJan 17.2006 — <a href="#" onclick="function();[B]return false[/B]">link</a>

that will prevent the HTML action controlled by href
Copy linkTweet thisAlerts:
@CharlesJan 17.2006 — Or, better yet:&lt;a href="version-for-the-JavaScript-free.html" onclick="function();return false"&gt;link&lt;/a&gt;
Copy linkTweet thisAlerts:
@BrettNooyenauthorJan 17.2006 — Thank you very much, makes total sense! ?
×

Success!

Help @BrettNooyen spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...