Dave's Brain

Browse - Programming Tips - How do I disable/enable a button with jQuery?

Date: 2010jun30
Updated: 2011nov24
Language: javaScript
Platform: web
Library: jQuery

Q.  How do I disable/enable a button with jQuery?

A.  Disable like this:

$('#mybutton').attr('disabled', true);
Enable like this:
$('#mybutton').attr('disabled', false); // or you can remove the attribute
You could make a wrapper function as so:
function enableButton(query, is_enabled) { $(query).attr('disabled', !is_enabled); }
Example use:
enableButton('#mybutton', false); // disables it enableButton('#mybutton', true); // enables it

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.