Home  >  Article  >  Web Front-end  >  Here are a few question-based titles based on your article content: Short & Simple: * How Do I Disable and Enable HTML Input Buttons? * Want to Control HTML Button States? Here\'s How! * Dynamic

Here are a few question-based titles based on your article content: Short & Simple: * How Do I Disable and Enable HTML Input Buttons? * Want to Control HTML Button States? Here\'s How! * Dynamic

Patricia Arquette
Patricia ArquetteOriginal
2024-10-27 00:20:30631browse

Here are a few question-based titles based on your article content:

Short & Simple:

* How Do I Disable and Enable HTML Input Buttons?
* Want to Control HTML Button States? Here's How!
* Dynamically Enable/Disable HTML Buttons: A Quick Guide

More Speci

How to Control the Enabled State of HTML Input Buttons

You want to have the option to disable and enable an HTML button dynamically. Here's how you can achieve this:

Using JavaScript

To disable the button, use the following code:

<code class="javascript">document.getElementById("Button").disabled = true;</code>

To enable the button, use:

<code class="javascript">document.getElementById("Button").disabled = false;</code>

Using jQuery

For jQuery versions prior to 1.6:

Disable the button:

<code class="javascript">$('#Button').attr('disabled','disabled');</code>

Enable the button:

<code class="javascript">$('#Button').removeAttr('disabled');</code>

For jQuery versions 1.6 and later:

Disable the button:

<code class="javascript">$('#Button').prop('disabled', true);</code>

Enable the button:

<code class="javascript">$('#Button').prop('disabled', false);</code>

Code Demo

Refer to the provided demos for practical examples of how to disable and enable a button dynamically.

The above is the detailed content of Here are a few question-based titles based on your article content: Short & Simple: * How Do I Disable and Enable HTML Input Buttons? * Want to Control HTML Button States? Here\'s How! * Dynamic. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn