// Polyfill for Element.matches() for older browsers if (!Element.prototype.matches) { Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector; } // Polyfill for Element.closest() for older browsers if (!Element.prototype.closest) { Element.prototype.closest = function(selector) { var element = this; while (element) { if (element.matches(selector)) return element; element = element.parentElement; } return null; }; } document.addEventListener('click', function(event) { var button = event.target.closest('.flip-card'); if (button) { var scene = button.closest('.scene'); var boxFlip = scene.querySelector('.box-flip'); boxFlip.classList.toggle('is-flipped'); } });