Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.attr('disabled', 'disabled') or .attr('disabled', true) for disabling input

Tags:

jquery

Both .attr('disabled', 'disabled') and .attr('disabled', true) work in my code, but I'm just wondering: which among the two is more efficient and/or which is more used? Is there really a difference? Performance-wise, maybe?

like image 427
pistachioesque Avatar asked Jul 25 '14 02:07

pistachioesque


People also ask

What is attr disabled?

The Boolean disabled attribute, when present, makes the element not mutable, focusable, or even submitted with the form. The user can neither edit nor focus on the control, nor its form control descendants.

How do I remove attr disabled?

Projects In JavaScript & JQuery To remove disabled attribute using jQuery, use the removeAttr() method. You need to first remove the property using the prop() method. It will set the underlying Boolean value to false.

How to use disabled attribute in JavaScript?

The disabled attribute can be set to keep a user from using the element until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the element usable again.

What is the disabled attribute?

Definition and Usage The disabled attribute is a boolean attribute. When present, it specifies that the <input> element should be disabled. A disabled input element is unusable and un-clickable.

What is the HTML <input> disabled attribute?

HTML <input> disabled Attribute 1 Definition and Usage. The disabled attribute is a boolean attribute. When present, it specifies that the <input> element... 2 Browser Support. The numbers in the table specify the first browser version that fully supports the attribute. 3 Syntax. More ...

How to use ATTR () function in JavaScript?

This attr () function is first applied to the element which is input element or input field or input box then it is followed by the dot operator along with attr () function in which there are two parameters passed to this function and both the parameters are declared as “disabled” this is done when we are disabling the matched or specified element.

Why do disabled attributes not work on form controls?

If the disabled attribute is specified on a form control, the element and its form control descendants do not participate in constraint validation. Often browsers grey out such controls and it won't receive any browsing events, like mouse clicks or focus-related ones.


1 Answers

Should not make any difference. But from jQuery 1.6+ you should use:

$('input').prop('disabled', true);
like image 61
rjpedrosa Avatar answered Oct 12 '22 00:10

rjpedrosa