0

For buttons, we have the onclick attribute to call a JavaScript function, but how to make a hyperlink work like a button?

In addition, how to use a hyperlink to submit a form or do anything else a button can do?

OneZero
  • 11,556
  • 15
  • 55
  • 92
  • 2
    possible duplicate of [Href tag for JavaScript links: "#" or "javascript:void(0)"?](http://stackoverflow.com/questions/134845/href-tag-for-javascript-links-or-javascriptvoid0) – Paul Sasik Jun 08 '12 at 01:05

3 Answers3

3
<a href="javascript:void(0)" onclick="someFunction()">Click</a>
WojtekT
  • 4,735
  • 25
  • 37
  • You probably want to describe the fact of returning true/false either as a return on the called function, or as a stacked command – Tom Gullen Jun 08 '12 at 01:07
2
<a href="#" onclick="doSomething(); return false;">Click</a>
Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
0
<a href=# onClick=alert('hi.'),false>Click</a>

a { -moz-appearance: button; } // or -webkit-

https://jsfiddle.net/Dezain/r3g9e7a2/

Thielicious
  • 4,122
  • 2
  • 25
  • 35