JQuery prop()
The prop()
method in jQuery is used to get or set properties of an HTML element. It is a shorthand method for the attr()
method and should be used for properties such as checked, disabled, selected, and readonly attributes.
Syntax
Here is the syntax for using the prop()
method:
$(selector).prop(propertyName, value)
selector
- the HTML element(s) to be selectedpropertyName
- the name of the property to be set or retrievedvalue
(optional) - the value to be set for the property
Use
The prop()
method is commonly used when working with form elements. For example, it can be used to check if a checkbox is checked, disable a form field, or select an option in a dropdown list.
Example
Here is an example of using the prop()
method to set the disabled
property of a form field: