Open In App

JQuery deferred.resolve() method

Last Updated : 07 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

This deferred.resolve() method in JQuery is used to resolve a Deferred object and call any doneCallbacks with the given arguments.

Syntax

deferred.resolve([args])

Parameters

  • args: This is optional parameters and is arguments which are passed to the doneCallbacks.

Return Value

This method returns the deferred object. There are two examples discussed below:

Example: In this example, The resolve() is called with the arguments.

HTML
<!DOCTYPE HTML>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0">
    <title>JQuery | deferred.resolve() method</title>
    
  	<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
    
  	<style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f8f9fa;
            margin: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            color: #343a40;
            text-align: center;
        }

        .container {
            background: #ffffff;
            padding: 30px;
            border-radius: 12px;
            box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
            max-width: 600px;
            width: 90%;
        }

        h1 {
            color: #28a745;
            margin-bottom: 20px;
        }

        p {
            font-size: 1.1em;
            line-height: 1.6;
            color: #495057;
            transition: color 0.3s ease;
        }

        button {
            padding: 10px 20px;
            font-size: 1em;
            color: #ffffff;
            background-color: #007bff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        button:hover {
            background-color: #0056b3;
        }

        footer {
            margin-top: 20px;
            font-size: 0.9em;
            color: #28a745;
        }
    </style>
</head>
  
<body>
    <div class="container">
        <h1>GeeksForGeeks</h1>
        <p id="GFG_UP">JQuery | deferred.resolve() method</p>
        <button id="clickBtn">Click here</button>
        <p id="GFG_DOWN"></p>
        <footer>© 2024 GeeksforGeeks. All rights reserved.</footer>
    </div>
    <script>
        $(document).ready(function(){
            $('#clickBtn').on('click', function(){
                var def = $.Deferred();
                def.done(function(val, div){
                    $(div).append(val);
                });
                def.resolve(
                    'resolve() method is called with arguments and Deferred object is resolved', 
                    '#GFG_DOWN'
                );
            });
        });
    </script>
</body>
  
</html>

Output

JQuery-1
Output : deferred.resolve() method

Next Article

Similar Reads