1

Javascript Jquery code

want to fade in and fade out the background color on div

    $("div").focusin(function(){
        $(this).css("background-color","green"),fadein(5000);
    });
    $("div").focusout(function(){
        $(this).css("background-color","white"),fadein(5000);
    });

})

HTMl code

<div>
  first name:
  <input type="text" name="" id="" />
  last name:
  <input type="text" name="" id="" />
</div>
SnazzyGill
  • 13
  • 5
  • Does this answer your question? [jQuery animate backgroundColor](https://stackoverflow.com/questions/190560/jquery-animate-backgroundcolor) – Martin Apr 24 '21 at 19:15

1 Answers1

1

Unless you specifically want to do it with jquery, there is an easy css-only method:

input
{
  transition: background-color 5s ease;
  background-color: white;
}
input:focus
{
  background-color: green;
}
<div>
  first name:
  <input type="text" name="" id="">
  last name:
  <input type="text" name="" id="">
</div>
vanowm
  • 9,466
  • 2
  • 21
  • 37