---
title: "Use :enable and :disable selectors via jQuery"  
description: "Use :enable and :disable selectors via jQuery"  
author: "Ethan Karla"  
published: 2021-07-28  
updated: 2023-11-26  
canonical: https://www.mindstick.com/forum/156647/use-enable-and-disable-selectors-via-jquery  
category: "jquery"  
tags: ["jquery"]  
reading_time: 2 minutes  

---

# Use :enable and :disable selectors via jQuery

How to use :enable and :[disable](https://www.mindstick.com/forum/12901/how-to-disable-enable-input-box-in-aspx-with-value-from-sql) [selectors](https://www.mindstick.com/interview/22831/what-is-the-use-of-selectors-in-objective-c) via jQuery?

## Replies

### Reply by Aryan Kumar

In jQuery, you can use the **prop()** method to enable or disable form elements. Here's an example that shows how to use the **prop()** method to enable and disable a button based on the value of a checkbox:

```plaintext
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Enable/Disable Selectors via jQuery</title>
  <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
</head>
<body>

<form>
  <label for="enableCheckbox">Enable/Disable Button</label>
  <input type="checkbox" id="enableCheckbox">

  <button id="myButton" type="button">Click Me!</button>
</form>

<script>
  $(document).ready(function() {
    // Initially, disable the button
    $('#myButton').prop('disabled', true);

    // Change the button state based on the checkbox
    $('#enableCheckbox').on('change', function() {
      // If the checkbox is checked, enable the button; otherwise, disable it
      $('#myButton').prop('disabled', !this.checked);
    });
  });
</script>

</body>
</html>
```

In this example:

- The button (**#myButton**) is initially disabled using **$('#myButton').prop('disabled', true);**.
- The state of the button is changed based on the checkbox (**#enableCheckbox**) using the **change** event. If the checkbox is checked, the button is enabled; otherwise, it is disabled.

You can adapt this example to your specific use case by adjusting the selectors and the conditions for enabling or disabling elements based on your application's requirements.


---

Original Source: https://www.mindstick.com/forum/156647/use-enable-and-disable-selectors-via-jquery

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
