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>
Community
  • 1
  • 1
Arshdeep
  • 4,281
  • 7
  • 31
  • 46

2 Answers2

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.

Navnath Godse
  • 2,233
  • 2
  • 23
  • 32
Amy B
  • 17,874
  • 12
  • 64
  • 83
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>
Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • SEO has nothing to do with it. – Amy B Nov 10 '10 at 19:48
  • 1
    @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... – Guffa Nov 10 '10 at 19:56
  • 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. – Amy B Nov 10 '10 at 20:46
  • From an accessibility standpoint, I would not use `` unless you have an explicit `taborder` attribute because it cannot otherwise receive `focus()`. Perhaps use ``? – Michael Mar 04 '14 at 14:31