(function() { 'use strict'; window.utils = window.utils || {}; window.utils.alert = function(alertEl) { alertEl.querySelector('.alert__close').addEventListener('click', function(event) { alertEl.classList.add('alert--invisible'); }); } })(); document.addEventListener('DOMContentLoaded', function() { // setup alerts Array.from(document.querySelectorAll('.alert')).forEach(function(alertEl) { window.utils.alert(alertEl); }); });