<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <title>ARIA div buttons</title>
    <style>
      div {
        background-color: rgb(240, 240, 240);
        font-size: 11px;
        font-family: sans-serif;
        border: 1px outset rgb(218, 218, 218);
        line-height: 20px;
        padding: 0 6px;
        width: 120px;
        text-align: center;
        border-radius: 5px;
        margin-right: 10px;
        cursor: pointer;
        display: inline-block;
      }

      div:hover, div:focus {
        font-weight: bold;
      }
    </style>
  </head>
  <body>

    <h2>ARIA div buttons</h2>

    <div data-message="This is from the first button" tabindex="0" role="button">Click me!</div>
    <div data-message="This is from the second button" tabindex="0" role="button">Click me too!</div>
    <div data-message="This is from the third button" tabindex="0" role="button">And me!</div>

    <script>
      const buttons = document.querySelectorAll('div');

      for(let i = 0; i < buttons.length; i++) {
        addHandler(buttons[i]);
      }

      function addHandler(button) {
        button.onclick = function(e) {
          let message = e.target.getAttribute('data-message');
          alert(message);
        }
      }

      document.onkeydown = function(e) {
        if(e.keyCode === 13) { // The Enter/Return key
          document.activeElement.onclick(e);
        }
      };
    </script>
  </body>
</html>
