10

Possible Duplicates:
Href for Javascript links: “#” or “javascript:void(0)”?
Why is it bad practice to use links with the javascript: “protocol”?

As question says . .

Which approach is better ?

<a href='javascript:func()' >blah</a>

or

<a href='#' onclick='func()' >blah</a>
4
  • 1
    Better for what? Maintainability? Browser compatibility? Something else? Commented Nov 10, 2010 at 19:41
  • 1
    I'm interested in this answer too. I would say from a compatibility standpoint, primarily. Commented Nov 10, 2010 at 19:42
  • @Oded if you can define form both point of view(or any other point of view) .. then it will very good thing to know . Commented Nov 10, 2010 at 19:44
  • possible dupe of stackoverflow.com/questions/134845/… Commented Nov 10, 2010 at 19:44

2 Answers 2

9

Neither.

Use this:

<a href="javascript-disabled-page" onclick="func(); return false;">blah</a>

That way if the user has JS disabled, they will be taken to javascript-disabled-page and the browsing experience isn't ruined.

Sign up to request clarification or add additional context in comments.

2 Comments

+1 for suggesting javascript-disabled-page .
still better: add the event handler from javascript itself. still +1 anyway
1

That depends on what you want to achieve. From a SEO perspective it's better to use links only for actual links, and use click events on other tags for things that doesn't navigate anywhere:

<span class="LinkLookalike" onclick="func();">blah</span>

4 Comments

SEO has nothing to do with it.
@Coronatus: SEO is mainly about content and links, and now you say that SEO has nothing to do with links? Perhaps you should tell Google about this revolutionary change...
SEO is about content and links ("mainly" isn't reliably true). In this case the links and SEO have nothing to do with each other because search spiders can't execute Javascript and would need to be incredibly dumb (which none are) to not deal with this common usage.
From an accessibility standpoint, I would not use <span/> unless you have an explicit taborder attribute because it cannot otherwise receive focus(). Perhaps use <button/>?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.