How to enable/disable a button using jQuery ? Last Updated : 30 Jul, 2024 Comments Improve Suggest changes Like Article Like Report Enabling/disabling a button using jQuery involves altering its functionality to either accept user input or not. This is typically done by manipulating its 'disabled' property or attribute through jQuery methods like `.prop()` or .attr().To enable/disable a button using jQuery, you'll need a basic HTML structure along with JavaScript/jQuery. Below is a simple code structure to get you started HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Button Enable/Disable</title> <script src= "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"> </script> </head> <body> <button id="myButton">Click Me</button> <script> $(document).ready(function(){ // jQuery code to enable/disable button // Add your code here }); </script> </body> </html> Examples of enabling/disabling a button using jQuery1. Using the .prop() method:Using .prop() in jQuery to enable/disable a button involves setting its 'disabled' property to true or false, providing efficient control over its interactivity based on application requirements and user interactions.Example: In this example we are using jQuery: Toggles button's 'disabled' property on click and double-click events for smooth user interaction using .prop() method. HTML <!DOCTYPE html> <html> <head> <script src= "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"> </script> </head> <body> <h3>Using the .prop() method</h3> <button id="update">update me</button> <div style="margin-top: 50px"> <button id="change">click me</button> </div> <script> $("#change").on("click", function () { $("#update").prop( "disabled", true ); }); $("#change").on( "dblclick", function () { $("#update").prop( "disabled", false ); } ); </script> </body> </html> Output:.prop() method Example Output2. Using the .attr() methodUsing the .attr() method in jQuery, you toggle the 'disabled' attribute of elements. Clicking a button disables another button, while double-clicking re-enables it, enhancing user interaction and functionality within web pages.Example: In this example we are using .attr() method to enable/disable button. Clicking disables another button; double-clicking re-enables it, enhancing user interaction and web functionality. HTML <!DOCTYPE html> <html> <head> <script src= "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"> </script> </head> <body> <h3>Using the .attr() method</h3> <button id="update">Update Me</button> <div style="margin-top: 50px;"> <button id="change">Click Me</button> </div> <script> $("#change").on("click", function () { $("#update").attr("disabled", "disabled"); }); $("#change").on("dblclick", function () { $("#update").removeAttr("disabled"); }); </script> </body> </html> Output:.attr() method Example output Comment More infoAdvertise with us Next Article How to enable/disable a button using jQuery ? debadebaduttapanda7 Follow Improve Article Tags : Web Technologies HTML JQuery Blogathon Blogathon-2021 jQuery-Methods jQuery-Questions +3 More Similar Reads How to Disable a Button in jQuery UI ? To disable a button in jQuery UI, we will be using disable() method which is discussed below: jQuery UI disable() method is used to completely disable the button. It returns the button element completely to its initial state. Syntax: $(".selector").button("disable") Parameters: This method does not 2 min read How to make a Disable Buttons using jQuery Mobile ? jQuery Mobile is a web based technology used to make responsive content that can be accessed on all smartphones, tablets and desktops. In this article, we will be making a Disable Button using jQuery Mobile. Approach: First, add jQuery Mobile scripts needed for your project. <link rel="stylesheet 1 min read How to disable or enable form submit button in jQuery? Enabling or disabling the form submit button based on a checkbox selection in jQuery. This ensures user compliance with terms and conditions before form submission. Syntax:$('#enabled').click(function () { if ($('#submit-button').is(':disabled')) { $('#submit-button').removeAttr('disabled'); } else 2 min read jQuery UI Buttonset enable() Method jQuery UI consists of GUI widgets, visual effects, and themes implemented using HTML, CSS, and jQuery. jQuery UI is great for building UI interfaces for the webpages. The jQuery UI buttonset widget is used to give a visual grouping for a group of related buttons. The jQuery UI buttonset enable() met 1 min read jQuery UI Button disable() Method jQuery UI consists of GUI widgets, visual effects, and themes implemented using HTML, CSS, and jQuery. jQuery UI is great for building UI interfaces for the webpages. The jQuery UI Button disable() method is used to disable the button widget. It does not accept any parameter. Syntax: $(".selector"). 1 min read jQuery UI Button disabled Option jQuery UI consists of GUI widgets, visual effects, and themes implemented using HTML, CSS, and jQuery. jQuery UI is great for building UI interfaces for the webpages. The jQuery UI Button disabled option is used to disable the button element if it set to true. Syntax: $( ".selector" ).button({ disab 1 min read How to disable buttons using AngularJS ? In this article, we will see how to disable the button using the particular directive in AngularJS. Sometimes, we need to disable the button, and link on the click event. This task can be accomplished by implementing the ng-disabled directive that is used to enable or disable HTML elements. Syntax: 2 min read jQuery UI Button enable() Method jQuery UI consists of GUI widgets, visual effects, and themes implemented using HTML, CSS, and jQuery. jQuery UI is great for building UI interfaces for the webpages. The jQuery UI Button enable() method is used to enable the disabled button element. It does not accept any parameter. Syntax: $(".sel 1 min read JavaScript- Disable and Enable Button in JS These are the following approaches to Disable and enable a Button in JavaScript:1. Using the disabled Attribute The code example toggles the 'myButton' state between enabled and disabled using the 'toggleButton'. Clicking the 'toggleButton' triggers the 'toggleButtonState' function, which checks if 2 min read jQuery UI Buttonset disable() Method jQuery UI consists of GUI widgets, visual effects, and themes implemented using HTML, CSS, and jQuery. jQuery UI is great for building UI interfaces for the webpages. The jQuery UI Buttonset widget is used to give a visual grouping for a group of related buttons. The jQuery UI Buttonset disable() me 1 min read Like