Here is the implementation of the logic.
<!DOCTYPE html>
<html>
<head>
<title>HTML dialog Tag</title>
</head>
<body>
<!-- Simple pop-up dialog box, containing a form -->
<dialog id="dialog">
<form method="dialog">
<h3> Hello</h3>
<menu>
<button id="close" type="reset">Close</button>
</menu>
</form>
</dialog>
<menu>
<button id="click">Click Me</button>
</menu>
<script>
(function()
{
var clickButton = document.getElementById('click');
var closeButton = document.getElementById('close');
var Dialog = document.getElementById('dialog');
// Update button opens a modal dialog
clickButton.addEventListener('click', function() {
Dialog.showModal();
});
// Form close button closes the dialog box
closeButton.addEventListener('click', function() {
Dialog.close();
});
})();
</script>
</body>
</html
Post any problem if encountered in the comments.
Thanks for visiting GIMIBITS.
Please share this post and like us on Facebook.
HITESH BHATIA
EDITOR IN CHIEF
Comments
Post a Comment