var btn = document.querySelector('button'); btn.addEventListener('click', popup); function popup() { var popwin = document.createElement('div'); document.body.append(popwin); setTimeout(popclose, 2000); function popclose() { for (var i=0; i<100; i++); { popwin.style.backgroundColor = 'rgba(123, 204, 91,',i/100,');'; if (i >= 100) { popwin.remove(); }; }; } } div { background-color: rgba(123, 204, 91, 0.5); width: 200px; height: 100px; } <button>Кнопка</button> There is such an attempt to make a smooth extinction of the window, but for some reason it does not work, what am I doing wrong?