How7oHow7o
  • Home
  • Tools
    • All Tools
    • Image Tools
    • Text & String Tools
    • Video Tools
    • Developer Tools
    • PDF Tools
    • Calculators & More
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Disable or Enable an Input with JavaScript or jQuery
Share
Notification Show More
Font ResizerAa
How7oHow7o
Font ResizerAa
  • Tools
  • Prank Screens
  • Learn
  • Blog
Search
  • Home
  • Tools
    • All Tools
    • Image Tools
    • Text & String Tools
    • Video Tools
    • Developer Tools
    • PDF Tools
    • Calculators & More
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Web Development > How to Disable or Enable an Input with JavaScript or jQuery
Web Development

How to Disable or Enable an Input with JavaScript or jQuery

how7o
By how7o
Last updated: May 22, 2026
4 Min Read
Disable and enable a form input with JavaScript and jQuery
SHARE

To disable or enable an input with JavaScript, set the element’s disabled property to true or false. In jQuery 1.6+, use .prop('disabled', true/false) — not .attr(), which is the most common mistake.

Contents
  • Vanilla JavaScript
  • jQuery 1.6+ — use .prop()
  • jQuery 1.5 and below — .attr() / .removeAttr()
  • Inside an event handler — use this
  • Disable a group of inputs together
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 with jQuery 3.7 and modern browsers. Originally published 2022-08-05, rewritten and updated 2026-05-17.

Vanilla JavaScript

// Disable
document.getElementById('input-id').disabled = true;

// Enable
document.getElementById('input-id').disabled = false;

The disabled property is a boolean on the element. Setting it to true immediately disables the control (no longer focusable, no value submitted); setting it back to false re-enables.

Disable / enable input — vanilla JS .disabled, jQuery .prop, this.disabled in event handlers

jQuery 1.6+ — use .prop()

// Disable
$("#input-id").prop('disabled', true);

// Enable
$("#input-id").prop('disabled', false);

Always .prop() for boolean states like disabled, checked, and selected — these are live DOM properties, not static HTML attributes.

jQuery 1.5 and below — .attr() / .removeAttr()

$("#input-id").attr('disabled', 'disabled');
$("#input-id").removeAttr('disabled');

Only relevant on legacy stacks pinned to a pre-1.6 jQuery. On anything modern, use .prop().

Inside an event handler — use this

$("input").on('change', function () {
    this.disabled = true;
});

this is the raw DOM element inside a jQuery handler, so this.disabled = true skips the jQuery wrapper entirely — works on every jQuery version and is slightly faster than $(this).prop('disabled', true).

Disable a group of inputs together

// Disable every input inside a form
document.querySelectorAll('#my-form input, #my-form select, #my-form textarea')
    .forEach(el => el.disabled = true);

// Or wrap them in a fieldset and disable the whole fieldset
document.getElementById('my-fieldset').disabled = true;

The <fieldset disabled> trick is the cleanest — disabling the parent fieldset disables every form control inside it in one operation.

Frequently asked questions

Why use .prop() instead of .attr() in jQuery?

disabled is a DOM property (a live boolean on the element), not an HTML attribute. .attr('disabled', false) doesn’t enable the element in older jQuery because the attribute is still present in HTML — only the property change actually flips the form control. .prop(), added in jQuery 1.6, sets the live property, which is what the browser checks.

What’s the difference between disabled and readonly?

A disabled input is completely inert: it can’t be focused, its value is not submitted with the form, and it gets the disabled styling (usually grey). A readonly input is still focusable and its value is submitted — it just rejects edits. Use readonly when you want the value to round-trip through the form; disabled when you want to exclude it.

How do I disable every input in a form at once?

Wrap them in a <fieldset> and toggle fieldset.disabled = true. Every form control inside the fieldset becomes disabled in one step, no per-element loop. To target specific subsets in JS, use form.querySelectorAll('input, select, textarea').forEach(el => el.disabled = true).

Can I disable an input using only CSS?

Not really — pointer-events: none and opacity: 0.5 make an input look disabled, but a keyboard user can still tab into it and edit. Only the disabled attribute or property actually prevents interaction and removes the value from form submission. Treat CSS as the visual layer; use the property for behavior.

Related guides

  • How to Check if a Checkbox Is Checked with jQuery
  • How to Check if an Element Is Visible or Hidden with jQuery
  • How to Add a Required Attribute to Input Fields in jQuery

References

jQuery .prop(): api.jquery.com/prop. HTML disabled attribute: developer.mozilla.org/en-US/docs/Web/HTML/Element/input#disabled. Difference between .prop() and .attr(): api.jquery.com/prop/#entry-longdesc.

TAGGED:formsJavaScriptjQuery

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Delete all lines in Vim with :%d How to Delete All Lines in a File with Vi or Vim
Next Article Duplicate a div into another div with jQuery clone How to Duplicate a DIV into Another DIV with jQuery
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

You Might Also Like

Set A4 paper size in CSS for printing
Web Development

How to Set A4 Paper Size in CSS for Print

5 Min Read
WordPress pre_get_posts scoped to a custom post type with is_post_type_archive
Web Development

How to Apply pre_get_posts on Custom Post Types in WordPress

8 Min Read
Make Select2 work inside a Bootstrap modal
Web Development

How to Use Select2 Inside a Bootstrap Modal

4 Min Read
Make ApexCharts.js take full width of its parent
Web Development

How to Make ApexCharts.js Take the Full Width of Its Parent

5 Min Read
How7oHow7o

Free browser-based tools, prank screens, and step-by-step tech tutorials. No signup, nothing uploaded.

  • Private by design — your files never leave your device
  • Instant — no signup, no install, no waiting
  • Always free — no trials, no watermarks, no paywalls

Tools

  • PDF Editor
  • Image Upscaler
  • JPEG Compressor
  • Password Generator
  • QR Code Generator
  • Video Trimmer
  • See all tools →

Pranks

  • Cracked Screen Prank
  • Fake Blue Screen (BSOD)
  • Fake Disk Format
  • Fake Low Battery
  • Fake Nintendo Switch Update Screen
  • Fake PlayStation Update Screen
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?