Html Prop
# jQuery prop() Method
[ jQuery HTML/CSS Methods](#)
## Example
Add and remove an attribute named "color":
$("button").click(function(){var $x = $("div"); $x.prop("color","FF0000"); $x.append("The color Attribute: " + $x.prop("color")); $x.removeProp("color"); });
[Try it Β»](#)
* * *
## Definition and Usage
The prop() method sets or returns the properties and values of the selected elements.
When this method is used to **return** property values, it returns the value of the first matched element.
When this method is used to **set** property values, it sets one or more property/value pairs for the set of matched elements.
**Note:** The prop() method should be used for retrieving property values, such as DOM properties (e.g., selectedIndex, tagName, nodeName, nodeType, ownerDocument, defaultChecked, and defaultSelected).
**Tip:** To retrieve HTML attributes, use the [attr()](#) method instead.
**Tip:** To remove properties, use the [removeProp()](#) method.
* * *
## Syntax
Return the value of a property:
$(_selector_).prop(_property_)
Set a property and value:
$(_selector_).prop(_property,value_)
Set a property and value using a function:
$(_selector_).prop(_property,_ function(_index,_ _currentvalue_))
Set multiple properties and values:
$(_selector_).prop({_property_:_value_, _property_:_value_,...})
| Parameter | Description |
| :--- | :--- |
| _property_ | Specifies the name of the property. |
| _value_ | Specifies the value of the property. |
| function(_index,currentvalue_) | A function that returns the property value to set. * _index_ - The index position of the element in the collection. * _currentvalue_ - The current property value of the selected element. |
* * *

## More Examples
[The difference between prop() and attr()](#)
prop() and attr() may return different values. This example demonstrates the difference when used to return the "checked" state of a checkbox.
* * jQuery HTML/CSS Methods](#)
YouTip