Here I am going to tell you how to make animation of color on click event using JavaScript. Using CSS and JavaScript in HTML we can make our page very attractive.
HTML CODE
  1. <html>
  2. <head>
  3. <title>animation</title>
  4. <style>
  5. #box {
  6. background: #36C;
  7. width: 640px;
  8. height: 480px;
  9. }
  10. h1 {
  11. color: #FF0;
  12. padding-top: 180px;
  13. padding-left: 150px;
  14. }
  15. h3 {
  16. color: #009;
  17. padding-left: 150px;
  18. }
  19. #form {
  20. padding-left: 150px;
  21. }
  22. </style>
  23. <script type="text/javascript">
  24. function changeBG(el, clr) {
  25. var elem = document.getElementById(el);
  26. elem.style.transition = "background 2.0s";
  27. elem.style.background = clr;
  28. }
  29. </script>
  30. </head>
  31. <body>
  32. <h3>CLICK ON ANY BUTTON</h3>
  33. <form id="form">
  34. input type="button" value="megenta" onClick="changeBG('box','#F0F')"/>
  35. <input type="button" value="green" onClick="changeBG('box','#0c0')" />
  36. <input type="button" value="black" onClick="changeBG('box','#000')" />
  37. </form>
  38. <div id="box">
  39. <h1>Hello i am Sanjay Singh</h1>
  40. </div>
  41. </body>
  42. </html>
Output
When we click on the magenta button and here I also set this default color
Now if we click on the green button
Now if we click on the black button