Button Examples

by Michael Ball

HTML

<div onclick="alert('clicked)">
  This is a div that can be clicked
</div>
<hr>
<button onclick="alert('clicked)">
  A real button
</button>
<!-- Notice: This has the ability to be focused with the board and can be triccked with SPACE or ENTER -->
<hr>
<a onclick="alert('clicked)">
  A link impersonating a button
</a>
<hr>
<div
  role="button"
  tabindex="0"
  onclick="alert('clicked')"
  onkeypress="handleKeyPress">
  A div that does all it needs to, to mimic a button
 </div>

JavaScript

function handleKeyPress(event) {
	console.log(event);
  console.log(this)
}