How to call Hook into dialog close event in jQuery UI ?
Last Updated :
21 Dec, 2022
In this article, we are going to learn how we can call Hook into a "dialog" close event in jQuery UI.
To call a hook into the dialog "close" event in jQuery UI, we will use the close event provided by the dialog widget. This event is fired when the dialog is closed. Let's understand what a hook is, a hook is a function that is executed at a specific point in the lifecycle of an element or widget. Hooks allow developers to add custom behavior to elements and widgets by attaching functions to be executed at specific points in the element or widget's lifecycle.
To attach a function to the close event, we can use the "on" method provided by the "dialog" widget. This method allows you to specify the event you want to attach the function to, as well as the function itself.
Syntax:
$(element).widget({
hookName: function(event, ui) {
// Code to be executed when the hook is called
}
});
Example 1: In this example, we will call a hook into the dialog close event and reveal the "GeeksforGeeks" logo on the webpage.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Close Hook into dialog close event.</title>
<link href=
"https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel="stylesheet">
<script src=
"https://code.jquery.com/jquery-1.10.2.js">
</script>
<script src=
"https://code.jquery.com/ui/1.10.4/jquery-ui.js">
</script>
<style>
.box{
height: 100px;
width: 100%;
font-size: 30px;
display: flex;
align-items: center;
justify-content: center;
opacity: 0;
color: Green;
}
</style>
</head>
<body>
<div id="dialog">
Close this dialog box to reveal the GeeksforGeeks Text.
</div>
<div class="box">
<h2>GeeksforGeeks</h2>
</div>
<script>
$("#dialog").dialog({
title: "GeeksforGeeks",
close: function() {
// The code will run when the dialog is closed.
$(".box").animate({opacity : 1})
}
});
</script>
</body>
</html>
Output:
Call Hook into dialog close event
Example 2: In this example, we will call the hook into the dialog close event and change the color of the text available on the webpage.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Close Hook into dialog close event.</title>
<link href=
"https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel="stylesheet">
<script src=
"https://code.jquery.com/jquery-1.10.2.js">
</script>
<script src=
"https://code.jquery.com/ui/1.10.4/jquery-ui.js">
</script>
<style>
.box{
height: 500px;
width: 100%;
font-size: 30px;
display: flex;
align-items: center;
justify-content: center;
}
</style>
</head>
<body>
<div id="dialog">
Close this dialog box to change the color of the text.
</div>
<div class="box">
<h2>GeeksforGeeks</h2>
</div>
<script>
$("#dialog").dialog({
title: "GeeksforGeeks",
close: function() {
// The code will run when the dialog is closed.
$(".box").css("color", "green");
}
});
</script>
</body>
</html>
Output:
Call Hook into dialog close event
Similar Reads
jQuery UI Dialog close Event jQuery UI Close event is triggered when the dialog box is closed. Learn more about jQuery selectors and events here. Syntax: $(".selector").dialog ( close: function( event, ui ) { console.log('closed') },Approach: First, add jQuery Mobile scripts needed for your project.<link href = "https://code
1 min read
jQuery UI Dialog create Event jQuery UI Create event is triggered when the dialog box is created. Learn more about jQuery selectors and events here. Syntax: $(".selector").dialog ( create: function( event, ui ) { console.log('created') },Approach: First, add jQuery Mobile scripts needed for your project.<link href = "https://
2 min read
jQuery UI dialog close() Method close() method is used to disable the dialog. This method does not accept any argument Syntax: $( ".selector" ).dialog("close"); Approach: First, add jQuery UI scripts needed for your project. <link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel = "stylesheet"
1 min read
jQuery UI Dialog open Event jQuery UI open event is triggered when the dialog box is opened. Syntax: Learn more about jQuery selectors and events here. $(".selector").dialog ( open: function( event, ui ) { console.log('opened') },Approach: First, add jQuery Mobile scripts needed for your project.<link href = "https://code.j
1 min read
jQuery Mobile Dialog create Event jQuery Mobile is a web-based technology designed to make responsive websites and apps that are accessible on all smartphone, tablet, and desktop devices. DialogWidget is used as a pop-up & can be used on any page to convert it into a modal dialog. In this article, we are going to learn the jQuer
2 min read
jQuery UI Dialog focus Event The Dialog box is the way to inform the user about something. It is a nice way to popup on the user window to show the information that will happen in the next or any kind of information the developer wants to clarify to the user should know. jQueryUI dialog method is used to create a basic dialog w
2 min read