1

I know you can get this working with an event listener, but is it possible to catch middle clicks with the onclick attribute in HTML?

For example:

<span onclick="alert('hi');">middle click me<span>

http://jsfiddle.net/cB8Qv/

Kirk Ouimet
  • 27,280
  • 43
  • 127
  • 177

2 Answers2

1

A middle click is still giving off a click to your system, so yes it does work. Depending on your system this can do weird things such as opening a new window. Not sure how this affects on-clicks. But they will work.

Jpm61704
  • 60
  • 2
  • 8
0

If you put this around your span instead of using the onClick you can also use middle clicks (in all browsers),but its called bad practice .

<a href="javascript:alert('hi');">
    <span>middle click me</span>
</a>
Vloxxity
  • 980
  • 1
  • 9
  • 30