Spread the word.

Share the link on social media.

Share
  • Facebook
Have an account? Sign In Now

Sign Up


Have an account? Sign In Now

Sign In


Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.


Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

Ha Giang Local Expert®

Ha Giang Local Expert® Logo Ha Giang Local Expert® Logo

Ha Giang Local Expert® Navigation

  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • Home
  • About Us
  • Blog
  • Contact Us

Share & grow the world's knowledge!

We want to connect the people who have knowledge to the people who need it, to bring together people with different perspectives so they can understand each other better, and to empower everyone to share their knowledge.

Ask A Question
Home/ Questions/Q 265
Next
canomi
  • 0
canomi
Asked: March 5, 20202020-03-05T10:05:48+07:00 2020-03-05T10:05:48+07:00In: Web Development

How to disable a button in jQuery dialog from a function ?

  • 0

The basic dialog window is an overlay positioned within the viewport and is protected from page content which is jQuery’s User Interface. To disable the button in a jQuery dialog from a function carried using jQuery based on the following approaches.

Approach 1:

  • In UI Dialog box, button as default class called ui-button so focus on it.
  • Create a function that should trigger dialog box in ready that is on page load.
  • Then use jQuery method prop(‘disabled’, true) to disable that button with class ui-button.

Syntax:

$(selector).dialog();
$(selector).prop('disabled', true);

Example: Below example illustrates how to disable a button in a jQuery dialog from a function with help of prop() method.

<!DOCTYPE html>
<html lang="en">
     
<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1">
     
    <link rel="stylesheet" href=
"//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
     
    <link rel="stylesheet" href=
"https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
 
    <script src=
        "https://code.jquery.com/jquery-1.12.4.js">
    </script>
     
    <script src=
        "https://code.jquery.com/ui/1.12.1/jquery-ui.js">
    </script>
     
    <style>
        .ui-widget-header {
            background: green;
            color: #ffffff;
        }
         
        #dialog {
            box-shadow: 1rem .5rem 1rem 
                rgba(0, 0, 0, .15) !important;
                 
            padding: 20px;
        }
    </style>
</head>
 
<body>
    <div id="dialog" title="jQuery UI Basic dialog">
         
        <p>
            This is the default dialog which is useful
            for displaying information. The dialog
            window can be moved, resized and closed
            with the 'x' icon or use close button below,
            but it is diable using jQuery's prop();
            method.
        </p>
         
        <button type="button" class=
            "ui-button ui-widget" title="Close">
            Close
        </button>
    </div>
     
    <script>
        $(function() {
             
            // Trigger dialog box
            $("#dialog").dialog();
             
            // attr() method applied here
            $(".ui-button").prop('disabled', true);
        });
    </script>
</body>
 
</html>

Output:

Approach 2:

  • In UI Dialog box, button as default class called ui-button so focus on it.
  • Create a function that should trigger dialog box in ready that is on page load.
  • Then use jQuery method attr(‘disabled’, true) to disable that button with class ui-button.

Syntax:

$(selector).dialog();
$(selector).attr('disabled', true);

Example: Below example illustrates how to disable a button in a jQuery dialog from a function with help of attr() method.

<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="utf-8">
     
    <meta name="viewport"
        content="width=device-width, initial-scale=1">
     
    <link rel="stylesheet" href=
"https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
 
    <script src="
        https://code.jquery.com/jquery-1.12.4.js">
    </script>
     
    <script src=
        "https://code.jquery.com/ui/1.12.1/jquery-ui.js">
    </script>
 
    <style>
        .ui-widget-header {
            background: red;
            color: #ffffff;
        }
         
        #dialog {
            box-shadow: 1rem .5rem 1rem rgba(
            0, 0, 0, .15)!important;
            padding: 20px;
        }
    </style>
</head>
 
<body>
    <div id="dialog"
        title="jQuery UI Basic dialog">
     
        <p>
            This is the default dialog which is
            useful for displaying information.
            The dialog window can be moved,
            resized and closed with the 'x'
            icon or use close button below,
            but it is diable using jQuery's
            attr(); method.
        </p>
         
        <button type="button" class=
            "ui-button ui-widget" title="Close">
            Close
        </button>
    </div>
     
    <script>
        $(function() {
             
            // Trigger dialog box
            $("#dialog").dialog();
             
            // attr() method applied here
            $(".ui-button").attr('disabled', true);
        });
    </script>
</body>
 
</html>

Output:

disable a buttonjquery
  • 0 0 Answers
  • 222 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    Leave an answer
    Cancel reply

    You must login to add an answer.


    Forgot Password?

    Need An Account, Sign Up Here

    Sidebar

    Stats

    • Questions 43
    • Answers 37
    • Posts 37
    • Comments 4
    • Best Answers 18
    • Users 176
    • Popular
    • Answers
    • Tags
    • canomi

      Ha Giang Loop - On Own By Rental Car?

      • 3 Answers
    • wordpress

      Ha Giang 3 days loop itinerary + Ban Gioc waterfalls

      • 2 Answers
    • Aaron Aiken

      Hire a car with driver in Ha Giang

      • 2 Answers
    • Anonymous

      is the ha giang loop dangerous? or safe?

      • 2 Answers
    • Aaron Aiken

      Where is the Phuong Thien Cave in Ha Giang?

      • 2 Answers
    • canomi
      canomi added an answer If you need a tourguide for you trip so you… January 9, 2021 at 8:54 pm
    • canomi
      canomi added an answer It’s true that you can visit Ha Giang at any… January 9, 2021 at 8:47 pm
    • mvbergen
      [Deleted User] added an answer I heard that from May to Oct is the best… January 9, 2021 at 8:40 pm
    • mvbergen
      [Deleted User] added an answer Hi Alex, I am also going to Ha Giang in… January 9, 2021 at 8:40 pm
    • Tony
      Tony added an answer The weather in March is good, little bit cold and… January 9, 2021 at 6:49 pm
    3 days loop analytics bootstrap modal cao bang car and driver car for rent in ha giang car rental in ha giang cave covid-19 treatment covid-19 vietnam disable a button drone vietnam english english speaking driver float value google ha giang ha giang homestay ha giang hostel ha giang hotel ha giang loop ha giang loop accidents ha giang loop advice ha giang loop tour ha giang market ha giang motorbike tour ha giang tour ha giang travel hire car html email ios mail javascript jquery jquery.click() local market multiple selected mysql noong lake northern vietnam onclick php rent motorbike upload multiple images wordpress yandex mail

    Top Members

    canomi

    canomi

    • 11 Questions
    • 161 Points
    Aaron Aiken

    Aaron Aiken

    • 0 Questions
    • 24 Points
    galaxy35

    galaxy35

    • 0 Questions
    • 20 Points
    • Meet The Team
    • Blog
    • About Us
    • Contact Us

    © 2020 Discy. All Rights Reserved
    With Love by VZN.VN.

    Explore

    • Home
    • Communities
    • Questions
      • New Questions
      • Trending Questions
      • Must read Questions
      • Hot Questions
    • Polls
    • Tags
    • Badges
    • Users
    • Help

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.