<!DOCTYPE html>
<html>
<head>
<style>
.focusedin {
background: green;
}
.focusedout {
background: blue;
}
</style>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<meta charset="utf-8">
<title>Set background color of an element when the element gets focus or loses focus</title>
</head>
<body>
<div>
First name: <input type="text"><br>
Last name: <input type="text">
</div>
</body>
</html>
HTML Code:
JavaScript Code :