const myDiv = document.getElementById("myDiv"); const myButton = document.getElementById("myButton"); function decreaseWidth() { let width = myDiv.offsetWidth; if (width <= 0) { clearInterval(interval); } else { width--; myDiv.style.width = width + "px"; } } myButton.addEventListener("click", function() { const interval = setInterval(decreaseWidth, 10); });