function toggleModal()
{
    document.getElementById('modal').classList.toggle('hidden');
}

document.addEventListener('click', function(event) {
    if(!document.getElementById('modal').classList.contains('hidden') && !event.target.closest('.modal') && !event.target.closest('.openModal')){
        toggleModal()
    }
})