Description
The .prop() method sets or returns property values of selected elements.
Return Property Value
Get the value of a property for the first element in the set of matched elements.
v1.6
This method has the form:
.prop(propertyName )
Parameter | Description |
---|---|
propertyName | Specifies the name of the property to get |
Return Value
This form returns a String object.
Set Property/Value
Set one or more properties for the set of matched elements.
v1.6
This method has the alternate form:
.prop(propertyName,value)
Parameter | Description |
---|---|
propertyName | Specifies the name of the property |
value | Specifies the value to set for the property |
Return Value
This form returns a jQuery object.
Set Multiple Attribute/Value Pairs
Set one or more properties for the set of matched elements.
v1.6
This method has the alternate form:
.prop(map)
Parameter | Description |
---|---|
map | Specifies a map of property-value pairs to set |
Return Value
This form returns a jQuery object.
Set Attribute/Value Using a Function
Using a function to set one or more properties for the set of matched elements.
v1.6
This method has the alternate form:
.prop(propertyName,function(index,oldPropertyValue))
Parameter | Description |
---|---|
propertyName | Specifies the name of the property |
function(index, oldPropertyValue) |
Specifies a function that returns the property value to set.
|
Return Value
This form returns a jQuery object.
Examples
Set the width attribute of an image:
$("button").click(function(){
$("img").prop("width","150");
});