First, the background should be empty, after clicking on the button to start the animation, a square appears and begins to rotate, after pressing the delete button, this square is deleted and a blank background returns.
<!DOCTYPE html> <html> <head> <style type="text/css"> .square{ width: 80px; height: 80px; margin: 30px auto; background-color: #A52A2A; animation-name: spin; animation-duration: 2s; } @keyframes spin{ 0%{ transform: rotate(0deg); } 100%{ transform: rotate(360deg); } } </style> </head> <body> <div class="square"> </div> <script type="text/javascript"> btn1=document.createElement('BUTTON'); // ΡΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΠΊΠ½ΠΎΠΏΠΊΠΈ btn1.id='cmd1'; // id ΠΊΠ½ΠΎΠΏΠΊΠΈ btn1.onclick = function(){ // ΡΡΠ½ΠΊΡΠΈΡ ΠΏΡΠΈ ΠΊΠ»ΠΈΠΊΠ΅ ΠΏΠΎ Π½Π΅ΠΉ } btn1.textContent ='Π½Π°ΡΠ°ΡΡ Π°Π½ΠΈΠΌΠ°ΡΠΈΡ'; // ΠΈΠΌΡ ΠΊΠ½ΠΎΠΏΠΊΠΈ document.body.appendChild(btn1); // Π½ΡΠΆΠ½ΠΎ Π΄Π»Ρ Π΄ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΡ ΠΊΠ½ΠΎΠΏΠΊΠΈ btn2=document.createElement('BUTTON'); // Π²ΡΠΎΡΠ°Ρ ΠΊΠ½ΠΎΠΏΠΊΠ° btn2.id='cmd2'; btn2.onclick = function(){ } btn2.textContent ='ΡΠ΄Π°Π»ΠΈΡΡ Π°Π½ΠΈΠΌΠ°ΡΠΈΡ'; // ΠΈΠΌΡ ΠΊΠ½ΠΎΠΏΠΊΠΈ document.body.appendChild(btn2); </script> </body> </html>