Append text as you type

Description

The following code shows how to append text as you type.

Example


<html>
<head>
<script
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(<!--from  w ww  .ja va 2s.  com-->
      function() {
        $("input").keypress(
            function(e) {
              var c = String.fromCharCode(e.which);
              $("p").append($("<span/>")).children(":last")
                  .append(document.createTextNode(c));
              $("div").text(e.which);
            });
      });
</script>
</head>
<body>
<body>
  type some letters
  <input type="text" />
  <p>Add text -</p>
  <div></div>

</body>
</html>

Click to view the demo





















Home »
  jQuery »
    jQuery Example »




Animation
DOM
Event
Form
List
Select
Style
Table
Utilities