Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>jQuery UI - Dialog buttons option</title> <link rel="stylesheet" href="https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.13.2/jquery-ui.min.js"></script> <style> body{font-family:Arial, sans-serif; padding:20px;} #log{font-weight:bold;color:#04AA6D;margin-top:10px;} </style> </head> <body> <h3>Dialog with OK / Cancel buttons</h3> <button id="openBtn">Open Dialog</button> <div id="log"></div> <div id="dialog" title="Confirm action" style="display:none;"> <p>Are you sure you want to continue?</p> </div> <script> $(document).ready(function(){ $("#dialog").dialog({ autoOpen: false, modal: true, buttons: { "OK": function(){ $("#log").text('You clicked "OK".'); $(this).dialog("close"); }, "Cancel": function(){ $("#log").text('You clicked "Cancel".'); $(this).dialog("close"); } } }); $("#openBtn").on("click", function(){ $("#dialog").dialog("open"); }); }); </script> </body> </html>
Output