Skip to content

Instantly share code, notes, and snippets.

@greggman
Last active September 28, 2021 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greggman/d8f2de7666b5ea6b2427f63c66603657 to your computer and use it in GitHub Desktop.
Save greggman/d8f2de7666b5ea6b2427f63c66603657 to your computer and use it in GitHub Desktop.
<dialog> element
/*bug-in-github-api-content-can-not-be-empty*/
<dialog id="myDialog">
<div>this is a dialog</div>
<button id="close" type="button">close</button>
</dialog>
<button id="show" type="button">show dialog</button>
const dialogElem = document.querySelector('#myDialog');
const buttonElem = document.querySelector('#show');
const closeElem = document.querySelector('#close');
closeElem.addEventListener('click', (e) => {
dialogElem.close();
});
buttonElem.addEventListener('click', () => {
dialogElem.showModal();
});
{"name":"<dialog> element","settings":{},"filenames":["index.html","index.css","index.js"]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment