function closest(target, selector) { while (target) { if (target.matches && target.matches(selector)) return target; target = target.parentNode; } return null; } if (closest(event.target, '.popul')) return;