jQuery keydown() work with keyup()

Introduction

Enter your name in the input field above.

It will change background color on keydown and keyup.

View in separate window


<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>//from   w w  w  .j av  a 2s.  c o  m
<script>
$(document).ready(function(){
  $("input").keydown(function(){
    $("input").css("background-color", "yellow");
  });
  $("input").keyup(function(){
    $("input").css("background-color", "pink");
  });
});
</script>
</head>
<body>

Enter your name: <input type="text">

</body>
</html>



PreviousNext

Related