Skip to content

Instantly share code, notes, and snippets.

@anacampesan
Created December 5, 2018 15:28
Show Gist options
  • Save anacampesan/28e267198527627d6d9e0d76ced206c4 to your computer and use it in GitHub Desktop.
Save anacampesan/28e267198527627d6d9e0d76ced206c4 to your computer and use it in GitHub Desktop.
Simple implementation of modals
<html>
<head>
<style>
.modal {
display: none;
}
.modal-open {
display: block;
}
</style>
</head>
<body>
<div class="modal" id="modal">
<h1>My modal</h1>
</div>
<button type="button" class="js-modal">Open modal</button>
<script>
document.addEventListener('click', function(e) {
if (e.target.classList.contains('js-modal')) {
document.getElementById('modal').classList.toggle('modal-open');
}
}, false);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment