jQuery: Best way to disabled input

Which is best?
$('#xyz').attr("disabled", true); 
$('#xyz').attr("disabled", "true"); 
$('#xyz').attr("disabled", "disabled"); 

Open in new window

LVL 16
hankknightAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ProculopsisConnect With a Mentor Commented:
I prefer:

$('#xyz').attr( { disabled: true } );

because you can add more stuff:

$('#xyz').attr( { disabled: true, value: "Locked" } );

works with prop too:

$('#xyz').prop( { disabled: true } );
$('#xyz').prop( { disabled: true, value: "Locked" } );
0
 
leakim971Connect With a Mentor PluritechnicianCommented:
$('#xyz').attr("disabled", "disabled"); ¿
or :
$('#xyz').attr("disabled", ""); ¿

http://www.w3.org/TR/html-markup/input.submit.html

in the jQuery plugin you can find this line :
elem.setAttribute( name, "" + value );

Open in new window


where elem is your input
name is the disabled attribute
the second argument is a string
0
 
robertarkConnect With a Mentor Commented:
Use .prop() - http://api.jquery.com/prop/

$('#elem').prop('disabled', true)
$('#elem').prop('disabled', false)

Open in new window

0
 
sonawanekiranConnect With a Mentor Commented:
If you are using latest version of jquery then use prop otherwise $('#xyz').attr("disabled", "disabled");
0
All Courses

From novice to tech pro — start learning today.