Disable/Enable an element using jQuery

You must have come across a situation where you have to make any element disable or enable.There are couple of ways using them you can enable/disable any element using jquery. jQuery really makes your task very easy. In below given example, I have disabled a textbox with id "txtName".

Approach 1

$("#txtName").attr("disabled", true);

Approach 2

$("#txtName").attr("disabled", "disabled");

If you wish to enable any element then you just have to do opposite of what you did to make it disable. However jQuery provides another way to remove any attribute.

Approach 1

$("#txtName").attr("disabled", false); 

Approach 2

$("#txtName").attr("disabled", ""); 

Approach 3


That's is. This is how you enable or disable any element using jQuery.

Feel free to contact me for any help related to jQuery. I will gladly help you.

Responsive Menu
Add more content here...