Dave's Brain

Browse - programming tips - jquery disable enable button

Date: 2010jun30
Updated: 2011nov24
Language: javaScript
Platform: 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
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, 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.
Advertisements: