.prop()
.prop( propertyName )Returns: Anything
Description: Get the value of a property for the first element in the set of matched elements.
-
version added: 1.6.prop( propertyName )
-
propertyNameType: StringThe name of the property to get.
-
The .prop()
method gets the property value for only the first element in the matched set. It returns undefined
for the value of a property that has not been set, or if the matched set has no elements. To get the value for each element individually, use a looping construct such as jQuery's .each()
or .map()
method.
Note: Attempting to change the type
property (or attribute) of an input
element created via HTML or already in an HTML document will result in an error being thrown by Internet Explorer 6, 7, or 8.
Attributes vs. Properties
The difference between attributes and properties can be important in specific situations.
Before jQuery 1.6, the .attr()
method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior.
As of jQuery 1.6, the .prop()
method provides a way to explicitly retrieve property values, while .attr()
retrieves attributes.