Search This Blog

Mar 20, 2013

DOM Manipulation: How to Enable / Disable Element in jQuery

What I love about jQuery is its effectiveness in dealing with DOM manipulation. You can easily select, add or remove classes in your html document. You can also manipulate html attributes on the fly. For example if you want to disable / enable element, all you have to do is to set disabled attribute to "disabled" using the following code.

/* to disable */ 
$('.myElement').attr('disabled', 'disabled'); 

To enable it just simply removed the added "disabled" attribute or you can assign an empty string value to disabled attribute.

$('.myElement').attr('disabled', '');  




Cheap VPS Hosting UK Service said...

For people coming from Google: Note that this post is out of date. You should use the .prop method in 1.6+:

$('element').prop('disabled', true);
$('element').prop('disabled', false);

Anonymous said...

Thanks for sharing...

Sinelogix said...

Hey guys great post and good information
website development company in bangalore