Q:

Set background color of an element when the element (or any elements inside it) gets focus or loses focus using jquery

0

Set background color of an element when the element (or any elements inside it) gets focus or loses focus using jquery

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

HTML Code:

<!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>

JavaScript Code :

$("div").focusin(function(){
        $(this).attr('class', 'focusedin');
    });

 $("div").focusout(function(){
        $(this).attr('class', 'focusedout');
    });

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now