Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>jQuery 1.6+</h2> <p>To change the <code>disabled</code> property you should use the <a href="http://api.jquery.com/prop" rel="noreferrer"><code>.prop()</code></a> function.</p> <pre><code>$("input").prop('disabled', true); $("input").prop('disabled', false); </code></pre> <h2>jQuery 1.5 and below</h2> <p>The <code>.prop()</code> function doesn't exist, but <a href="http://api.jquery.com/attr" rel="noreferrer"><code>.attr()</code></a> does similar:</p> <p>Set the disabled attribute.</p> <pre><code>$("input").attr('disabled','disabled'); </code></pre> <p>To enable again, the proper method is to use <a href="//api.jquery.com/removeAttr" rel="noreferrer"><code>.removeAttr()</code></a></p> <pre><code>$("input").removeAttr('disabled'); </code></pre> <h2>In any version of jQuery</h2> <p>You can always rely on the actual DOM object and is probably a little faster than the other two options if you are only dealing with one element:</p> <pre><code>// assuming an event handler thus 'this' this.disabled = true; </code></pre> <p>The advantage to using the <code>.prop()</code> or <code>.attr()</code> methods is that you can set the property for a bunch of selected items.</p> <hr> <p><strong>Note:</strong> In 1.6 there is a <a href="//api.jquery.com/removeProp" rel="noreferrer"><code>.removeProp()</code></a> method that sounds a lot like <code>removeAttr()</code>, but it <strong>SHOULD NOT BE USED</strong> on native properties like <code>'disabled'</code> Excerpt from the documentation:</p> <blockquote> <p>Note: Do not use this method to remove native properties such as checked, disabled, or selected. This will remove the property completely and, once removed, cannot be added again to element. Use .prop() to set these properties to false instead.</p> </blockquote> <p>In fact, I doubt there are many legitimate uses for this method, boolean props are done in such a way that you should set them to false instead of "removing" them like their "attribute" counterparts in 1.5</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload