The .prop() method gets or sets DOM properties on matched elements. This tutorial covers all four API overloads (getter, name/value setter, plain object, callback setter), the critical difference between properties and attributes, comparisons with .attr(), .val(), and .removeProp(), and five official jQuery demos.
01
Getter
First element only
02
Setter
Name + value
03
Object
Multiple props
04
Callback
Per element
05
vs .attr()
Prop vs markup
06
Since 1.6
Core API
Fundamentals
Introduction
DOM elements expose properties in JavaScript — live values that reflect current state: whether a checkbox is checked, an input is disabled, or a select option is selected. When you need to read or change that runtime state, jQuery provides .prop().
Introduced in jQuery 1.6, .prop() explicitly separates properties from attributes. Before 1.6, .attr() sometimes returned property values for certain names, causing inconsistent behavior across browsers. Now .attr() handles HTML attributes and .prop() handles DOM properties — each with a clear role.
Use .prop() for checked, disabled, selected, and selectedIndex on form elements. For typed input text, prefer .val() over .prop('value'). For markup values like href and src, use .attr() instead.
Concept
Understanding the .prop() Method
Given a jQuery object representing one or more DOM elements, .prop() either reads a property from the first element (getter) or writes properties to every matched element (setter). Getters return any JavaScript value or undefined if the property is not set. Setters return the original jQuery object for chaining.
Properties reflect live DOM state. For a checkbox, prop('checked') returns a boolean that updates when the user clicks. The checked attribute (read via attr('checked')) corresponds to defaultChecked — the initial HTML state — and does not change with user interaction.
💡
Beginner Tip
$("input").prop("checked") reads the live checked state from the first matched input only. To set properties on every match, use the setter forms — .prop("disabled", true), a plain object, or a callback.
Foundation
📝 Syntax
jQuery .prop() accepts four argument forms:
1. Getter — read one property (since 1.6)
jQuery
.prop( propertyName )
propertyName — the name of the property to get.
Returns Anything or undefined for the first matched element only.
2. Setter — name and value (since 1.6)
jQuery
.prop( propertyName, value )
propertyName — the property to set on every matched element.
value — any value: boolean, number, string, or object.
3. Plain object — set multiple properties (since 1.6)
jQuery
.prop( properties )
properties — a plain object of property-value pairs applied to each matched element.
4. Callback setter — computed value per element (since 1.6)
jQuery
.prop( propertyName, function( index, oldPropertyValue ) {
// return value to set
} )
index — zero-based position of the element in the matched set.
oldPropertyValue — the element’s current property value.
this — the current DOM element. Return a value to set; return nothing to leave unchanged.
Return value
Getter — Anything or undefined (first element only).
Setter — the original jQuery object (for chaining).
Properties vs. attributes
Use .prop() for live DOM state. Use .attr() for HTML attributes in markup:
jQuery
// Properties — live DOM state on form controls
if ( $("input").prop("checked") ) { /* user checked it */ }
if ( $("option").prop("selected") ) { /* currently selected */ }
$("input").prop("disabled", true);
var idx = $("select").prop("selectedIndex");
// Attributes — initial HTML values (strings)
$("a").attr("href", "/about");
Boolean properties: checked
The checked attribute does not correspond to the checked property. Always test live state with .prop():
jQuery
// Cross-browser: is the checkbox currently checked?
if ( $("input").prop("checked") ) { /* yes */ }
if ( $("input").is(":checked") ) { /* yes */ }
// Wrong for live state — reflects initial HTML only
// $("input").attr("checked")
Unchecked: .attr('checked') → undefined, .prop('checked') → false
Checked: .attr('checked') → "checked", .prop('checked') → true
.prop() tracks live state — .attr() reflects initial HTML
How It Works
The checked attribute corresponds to defaultChecked, not the live checked property. Since jQuery 1.6, always use .prop("checked") or .is(":checked") to test checkbox state. See the .attr() tutorial for the attribute side of this comparison.
Example 2 — Official Demo: Disable All Checkboxes With an Object
Pass a plain object to set disabled: true on every checkbox at once.
All checkboxes become disabled and unclickable
.prop({ disabled: true }) sets the live disabled property
How It Works
The plain-object form applies each key-value pair to every matched element. Use .prop() — not .attr('disabled') — to control whether form controls accept user input.
Example 3 — Official Demo: Toggle Checkboxes With a Callback
Flip the checked property based on each element’s current value.
jQuery
$( "input[type='checkbox']" ).prop( "checked", function( i, val ) {
return !val;
});
Each click inverts every checkbox
Checked → unchecked, unchecked → checked
How It Works
jQuery calls the callback once per matched element. The second argument val is the current property value. Returning !val toggles each checkbox independently. Returning undefined leaves the value unchanged.
📈 Practical Patterns
Combine properties with .val() for complete form control.
Example 4 — Enable Input and Set Checked State
Check a consent box, enable a text field, and set its value — properties plus .val().
checked=true, disabled=false, val=someValue
Use .prop() for boolean state — .val() for the text content
How It Works
.prop("disabled", false) re-enables the input. .val("someValue") sets the displayed text — the official jQuery API recommends .val() over .prop("value") for form values. Chain both on the same jQuery object.
Example 5 — Read selectedIndex From a Select
Get the zero-based index of the currently selected option — a property with no HTML attribute.
jQuery
var idx = $( "#colors" ).prop( "selectedIndex" );
var text = $( "#colors option:selected" ).text();
selectedIndex=2 (Blue)
Properties like selectedIndex have no attribute — use .prop()
How It Works
selectedIndex, tagName, nodeName, and nodeType are properties only — they cannot be set or read with .attr(). Since jQuery 1.6, .prop() is the correct API for these values.
Applications
🚀 Common Use Cases
Form validation gates — if (!$("#agree").prop("checked")) { /* block submit */ }.
Disable submit buttons — $("button[type=submit]").prop("disabled", true) during Ajax requests.
Toggle all checkboxes — $(".item").prop("checked", function(i, val){ return !val; }).
Bulk disable form fields — $("fieldset :input").prop({ disabled: true }).
Read select position — var idx = $("select").prop("selectedIndex") for index-based logic.
Enable fields on consent — $("#name").prop("disabled", false).val("") when user agrees.
🧠 How .prop() Reads and Writes Properties
1
Match elements
jQuery object holds one or more DOM nodes.
Input
2
Getter or setter?
One argument reads; two arguments or an object writes.
Mode
3
Access DOM property
jQuery reads or writes the live JavaScript property on each element.
DOM
4
🏷
Any value or jQuery object
Getter returns Anything/undefined (first only); setter returns same collection for chaining.
Important
📝 Notes
Available since jQuery 1.6 — all four overloads arrived together.
Getter returns value for the first element only; setters apply to all matches.
Use .prop() for checked, selected, disabled, and selectedIndex — not .attr().
Use .val() for getting and setting typed input text — not necessarily .prop('value').
Do not use .removeProp() on native DOM properties — set them explicitly instead.
Attempting to change the type property on an input already in the document throws in Internet Explorer 6, 7, and 8.
In IE prior to version 9, setting a property to a non-primitive value (object, function) can cause memory leaks — use .data() for complex values.
Compatibility
Browser Support
.prop() has been part of jQuery since 1.6+. It is the standard API for live DOM properties across jQuery 1.x, 2.x, 3.x, and 4.x. Native equivalent: direct property access (element.checked) — jQuery adds collection semantics, object/callback setters, and consistent cross-browser behavior.
✓ jQuery 1.6+
jQuery .prop()
Supported in jQuery 1.x, 2.x, 3.x, and 4.x across all modern browsers and IE with supported jQuery builds. Native equivalent: element[propertyName] — jQuery adds collection semantics, object/callback setters, and unified getter/setter API.
100%With jQuery loaded
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
.prop()Universal
Bottom line: Safe in any jQuery 1.6+ project. Use .prop() for live form state; .attr() for HTML attributes; .val() for input text.
Wrap Up
Conclusion
The jQuery .prop() method gets or sets DOM properties on matched elements. It is the standard way to read and write live form state like checked, disabled, and selectedIndex, and to bulk-update properties via a plain object or per-element computation via a callback.
Remember the official pattern: $("input").prop("checked", true) sets live checkbox state, while $("input").val("someValue") handles typed text. For markup attributes like href and src, use .attr(). Never call .removeProp() on native properties — set them to false or their default instead.
Use .val() for getting and setting input, textarea, and select text
Pass a plain object when setting multiple properties at once
Use the callback form to toggle or compute values per element
Use .attr() for standard HTML attributes — href, src, alt
❌ Don’t
Use .attr('checked') to test whether a checkbox is checked
Call .removeProp() on native properties like checked or disabled
Expect the getter to return values for every matched element
Set non-primitive values via .prop() in old IE — use .data() instead
Change type on inputs already in the document in IE6–8 without try/catch
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about .prop()
Properties in memory — attributes in markup.
5
Core concepts
get01
Getter
First only
API
set02
Setter
All matches
API
{}03
Object
Bulk set
Syntax
fn04
Callback
Toggle
Syntax
.val05
Form text
Use .val()
Compare
❓ Frequently Asked Questions
.prop() gets or sets DOM properties on matched elements. As a getter it returns the property value (any type or undefined) for the first element only. As a setter it updates properties on every matched element — by name/value, plain object, or callback function. Available since jQuery 1.6.
.prop() reads and writes live DOM properties — boolean state like checked, selected, and disabled that change at runtime. .attr() reads and writes HTML attributes — initial markup values (strings). For form state, always use .prop() or .is(':checked') — not .attr('checked'). See the .attr() tutorial for the attribute counterpart.
Prefer .val() for getting and setting the typed text of input, textarea, and select elements. .prop('value') can work but .val() is jQuery's dedicated method and handles edge cases consistently. Use .prop() for boolean and structural properties like checked, disabled, and selectedIndex.
No. The getter form .prop(name) returns the property value for only the first element in the set. To read each element individually, loop with .each() or .map(). Setters apply to every matched element.
No. Do not use .removeProp() on native DOM properties like checked or disabled — it leads to unexpected behavior. .removeProp() is for jQuery-added properties only. To reset form state, set the property explicitly: .prop('checked', false) or .prop('disabled', false).
The checked attribute corresponds to defaultChecked — the initial HTML state — and does not update when the user clicks. The checked property tracks live checkbox state as a boolean. After jQuery 1.6, .prop('checked') is the cross-browser way to test whether a checkbox is currently checked.
Did you know?
Before jQuery 1.6, there was no dedicated property API — .attr() sometimes returned live property values for names like checked, causing inconsistent behavior. The split into .attr() and .prop() fixed this permanently. The checked attribute actually maps to defaultChecked, not the live checked property — which is why .prop('checked') is the only reliable way to test current checkbox state.