Com And Hosting

Sometimes you need to disable or enable some elements in your document and jQuery makes this task easy. All you have to do is to set disabled attribute to “disabled”. You must have to reference the JQuery js file to work with the following script. You can download the latest jquery file from www.jquery.com website.

Example:

Include the jQuery script in head section –

<head>

<script type="text/javascript" src="js/jquery-1.4.1.js"></script>

</head>

The following example shows to disable the button on document load.

<script type="text/javascript">
$(document).ready(function(){
   // To disable  
   $('.someElement').attr('disabled', 'disabled');
});
</script>

In order to enable any disabled element you need to set the disabled attribute to empty string or remove it entirely like in the code below.

// To enable  
$('.someElement').removeAttr('disabled');

 // OR you can set attr to ""  
$('.someElement').attr('disabled', '');
2 thought on “Enable disable button using JQuery”
  1. Sometimes you need to disable or enable some elements in your document and jQuery makes this task easy. All you have to do is to set disabled attribute to “disabled”. You must have to reference the JQuery js file to work with the following script. You can download the latest jquery file from http://www.jquery.com website.

Leave a Reply

Your email address will not be published. Required fields are marked *