HTML Form How to - Change the background colour of a textbox on click








Question

We would like to know how to change the background colour of a textbox on click.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
input:focus {<!-- www.j  a  va2  s . c  om-->
  background-color: #ffa;
}
</style>
</head>
<body>
  <input id="inputElementID" />
</body>
</html>

The code above is rendered as follows: