<!-- keyupイベント -->
<div class="event">
  <h1 class="event_title">keyup</h1>
  <label for="key_label" class="key_label" id="key_label">
    message
    <input type="text" class="key">
  </label>
  <p class="key_text"></p>
</div>
html{
  font-size: 62.5%;
  font-family: "Yu Gothic Medium", "游ゴシック Medium", "YuGothic", "游ゴシック体", "ヒラギノ角ゴ Pro", "Hiragino Kaku Gothic Pro", "メイリオ", "Meiryo", sans-serif;
  letter-spacing: 0.1em;
  color: #222;
}

button, input{
  background-color: transparent;
  border: none;
  cursor: pointer;
  outline: none;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  display: block;
}

.event{
  width: 400px;
  margin: 30px auto;
}

.event_title{
  font-size: 2rem;
  padding: 0.8rem 0 1rem 2rem;
  background: #222;
  color: #fabe00;
  display: block;
}

/* keyup, keydownイベント */
.key_label{
  display: flex;
  align-items: center;
  font-size: 1.8rem;
  font-weight: bold;
  width: 400px;
  margin: 60px auto 30px;
}

.key{
  background: #fff;
  border: 2px solid #222;
  width: 300px;
  padding: 1rem;
  margin-left: 1rem;
}

.key.active{
  border: 2px solid #fabe00;
}

.key_text{
  width: 400px;
  height: 100px;
  margin: 0 auto;
  font-size: 1.8rem;
  line-height: 1.5;
  background: #eee;
  border-radius: 10px;
  padding: 1.5rem 2rem;
  box-sizing: border-box;
  position: relative;
}

.key_text:after{
  content: '';
  position: absolute;
  top: 50%;
  right: -15px;
  transform: translateY(-50%);
  display: inline-block;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 10px 0 10px 15px;
  border-color: transparent transparent transparent #eee;
}
//keyupイベント
$('.key').on('focus', function(){
  //activeクラスを追加する
  $(this).addClass('active');
});
$('.key').on('blur', function(){
  //activeクラスを消去する
  $(this).removeClass('active');
});

$('.key').on('keyup', function(){
  //入力したテキストを取得する
  var key = $(this).val();
  //取得したテキストを表示する
  $('.key_text').text(key);
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js