How to use onkeyup in javascript to add text to a div that isn't a textbox?

Viewed 5869

Let me start off saying that I am new to javascript.

I am trying to change a div's content to whatever letter I type in. So if I press "p" anywhere on the page, the div text will add that letter.

For example:

<html>
  <head>
    <script>
      document.getElementById("change").onkeyup = function() {myFunction()};

      function myfunction(){

      }
    </script>
  </head>
<body>
  <div id=change>p</div>
</body>
</html>

The function is where I am stuck.

I have seen a lot of examples involving typing in a textbox but none without one. If someone could guide me in the right direction, I would be very grateful.

2 Answers
Related