Skip Navigation Links



How to disable/enable an element with jQuery

Author : Virendra Dugar      Blog :jQuery By Example      Date: 7/17/2012 11:38:00 AM


You must have come across a situation where you have to make any element disable or enable. With jQuery, there are couple of ways using them you can enable/disable any element. 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 are using jQuery 1.7 or higher version then use prop(), instead of attr().
$("#txtName").prop("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
$("#txtName").removeAttr("disabled"); 
Again, if you are using jQuery 1.7 or higher version then use prop(), instead of attr(). That's is. This is how you enable or disable any element using jQuery.

Also read:


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

Bloggers

active bloggers in the last 24 hrs. Number shown in the bracket represents number of posts published in past 24 hrs,


other authors(110)

Fidarose Isha(3)

ravi dabas(3)

AMJAD KHAN(2)

Deepak(2)

MUNZ TDT(2)

Rakesh HP(2)

Raksha(2)

RWABhagidari.blogspot.com(2)

Sameena Prathap(2)

Srinivasan Sampathkumar(2)

vskesavarao(2)

Aarthi(1)

Aathira Nair(1)

Abha Iyengar(1)

Abhishek Mukherjee(1)

Abraham Tharakan(1)

admin(1)

Always Happy(1)

Anil(1)

anouradha bakshi(1)

Anu Varma(1)

Archana Kumar(1)

Beyond(1)

Champa(1)

Chandrika Shubham(1)

churumuri(1)

churumuri(1)

CM(1)

dawdayogesh(1)

Debolina Raja Gupta(1)

Dimple Maheshwari(1)

Disha(1)

Dr.K.P.R.RAJA(1)

Garfield Dsouza(1)

Govind Kumar(1)

Harimohan(1)

Harini Padmanabhan(1)

harish p i(1)

Hemu(1)

iBeingMe(1)

Iti(1)

k(1)

Kalamwali Bai(1)

Krithi Karthi(1)

Kunal Singh(1)

Lluvia....(1)

Madhavi Madhurakavi(1)

mahima(1)

Meena(1)

Megha Sarin(1)

mêlée(1)

mervin anto(1)

Mohd Salim(1)

Mythreyi(1)

Nandana(1)

Neelam Dadhwal(1)

Neeraja(1)

NG(1)

Nisha(1)

Nisheeth Ranjan(1)

Nivedita Thadani(1)

Nivedita Thadani(1)

Nona(1)

Nupur(1)

palash ranjan khound(1)

Pari Vasisht(1)

parth joshi(1)

Pheno Menon(1)

pinksocks(1)

Pradeep Chakraborty(1)

Pranshu(1)

Prasanta Bora(1)

Preety(1)

Priyadarshi Mishra(1)

Raja(1)

rajkumar r(1)

Rams(1)

Ray Titus(1)

rhythmnguitars(1)

Ritesh Agarwal(1)

Ritu(1)

rm(1)

RNA Corp(1)

Sabina Fatima Hussain(1)

saketvaani(1)

Sameena Prathap(1)

Sampada(1)

Santhosh Sivarajan(1)

Saravanan Sivaraman(1)

Shankha(1)

Shobha(1)

Shobhaa De(1)

sidhu352(1)

Smi..(1)

Sneha Sharma(1)

Sneo(1)

Sree(1)

Sriram Khé(1)

Sujoy Das(1)

Susan Deborah(1)

swapnil kochetaa(1)

Tarang Sinha(1)

Team G Square(1)

The Guy in the Hat ™(1)

Umasree(1)

unmanagedexe(1)

vanya(1)

Vidya Sury(1)

Vikram Karve(1)

vishesh unni raghunathan(1)


garland of Languages of India
an amalgamation of the diversified traditions
gracefully presented with novelty
http://www.haaram.com