{"id":592,"date":"2023-08-25T17:22:48","date_gmt":"2023-08-25T17:22:48","guid":{"rendered":"\/\/api.jquery.com\/?p=592"},"modified":"2026-01-20T17:35:21","modified_gmt":"2026-01-20T17:35:21","slug":"prop","status":"publish","type":"post","link":"https:\/\/api.jquery.com\/prop\/","title":{"rendered":".prop()"},"content":{"rendered":"Get the value of a property for the first element in the set of matched elements or set one or more properties for every matched element.<div class=\"toc\">\n<h4><span>Contents:<\/span><\/h4>\n<ul class=\"toc-list\">\n<li>\n<a href=\"#prop1\">.prop( propertyName )<\/a><ul><li><a href=\"#prop-propertyName\">.prop( propertyName )<\/a><\/li><\/ul>\n<\/li>\n<li>\n<a href=\"#prop2\">.prop( propertyName, value )<\/a><ul>\n<li><a href=\"#prop-propertyName-value\">.prop( propertyName, value )<\/a><\/li>\n<li><a href=\"#prop-properties\">.prop( properties )<\/a><\/li>\n<li><a href=\"#prop-propertyName-function\">.prop( propertyName, function )<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/div><article id=\"prop1\" class=\"entry method\"><h2 class=\"section-title\">\n<span class=\"name\">.prop( propertyName )<\/span><span class=\"returns\">Returns: <a href=\"http:\/\/api.jquery.com\/Types\/#Anything\">Anything<\/a><\/span>\n<\/h2>\n<div class=\"entry-wrapper\">\n<p class=\"desc\"><strong>Description: <\/strong>Get the value of a property for the first element in the set of matched elements.<\/p>\n<ul class=\"signatures\"><li class=\"signature\">\n<h4 class=\"name\">\n<span class=\"version-details\">version added: <a href=\"\/category\/version\/1.6\/\">1.6<\/a><\/span><a id=\"prop-propertyName\" href=\"#prop-propertyName\"><span class=\"icon-link\"><\/span>.prop( propertyName )<\/a>\n<\/h4>\n<ul><li id=\"prop-propertyName-propertyName\">\n<div><strong>propertyName<\/strong><\/div>\n<div>Type: <a href=\"http:\/\/api.jquery.com\/Types\/#String\">String<\/a>\n<\/div>\n<div>The name of the property to get.<\/div>\n<\/li><\/ul>\n<\/li><\/ul>\n<div class=\"longdesc\" id=\"entry-longdesc\">\n      <p>The <code>.prop()<\/code> method gets the property value for only the <em>first<\/em> element in the matched set. It returns <code>undefined<\/code> 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 <code>.each()<\/code> or <code>.map()<\/code> method.<\/p>\n      <div class=\"warning\">\n        <p><strong>Note:<\/strong> Attempting to change the <code>type<\/code> property (or attribute) of an <code>input<\/code> element created via HTML or already in an HTML document will result in an error being thrown by Internet Explorer 6, 7, or 8.<\/p>\n      <\/div>\n      <h4>Attributes vs. Properties<\/h4>\n      <p>The difference between <em>attributes<\/em> and <em>properties<\/em> can be important in specific situations. <strong>Before jQuery 1.6<\/strong>, the <code><a href=\"\/attr\/\">.attr()<\/a><\/code> method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior. <strong>As of jQuery 1.6<\/strong>, the <code>.prop()<\/code> method provides a way to explicitly retrieve property values, while <code>.attr()<\/code> retrieves attributes.<\/p>\n      <p>For example, <code>selectedIndex<\/code>, <code>tagName<\/code>, <code>nodeName<\/code>, <code>nodeType<\/code>, <code>ownerDocument<\/code>, <code>defaultChecked<\/code>, and <code>defaultSelected<\/code> should be retrieved and set with the <code>.prop()<\/code> method. Prior to jQuery 1.6, these properties were retrievable with the <code>.attr()<\/code> method, but this was not within the scope of <code>attr<\/code>. These do not have corresponding attributes and are only properties.<\/p>\n      <p>Concerning boolean attributes, consider a DOM element defined by the HTML markup <code>&lt;input type=\"checkbox\" checked=\"checked\" \/&gt;<\/code>, and assume it is in a JavaScript variable named <code>elem<\/code>:<\/p>\n      <table>\n        <tbody><tr>\n          <th>\n            <code>elem.checked<\/code>\n          <\/th>\n          <td>\n<code>true<\/code> (Boolean) Will change with checkbox state<\/td>\n        <\/tr>\n        <tr>\n          <th>\n            <code>$( elem ).prop( \"checked\" )<\/code>\n          <\/th>\n          <td>\n<code>true<\/code> (Boolean) Will change with checkbox state<\/td>\n        <\/tr>\n        <tr>\n          <th>\n            <code>elem.getAttribute( \"checked\" )<\/code>\n          <\/th>\n          <td>\n<code>\"checked\"<\/code> (String) Initial state of the checkbox; does not change<\/td>\n        <\/tr>\n        <tr>\n          <th>\n            <code>$( elem ).attr( \"checked\" )<\/code>\n            <em>(1.6+)<\/em>\n          <\/th>\n          <td>\n<code>\"checked\"<\/code> (String) Initial state of the checkbox; does not change<\/td>\n        <\/tr>\n        <tr>\n          <th>\n            <code>$( elem ).attr( \"checked\" )<\/code>\n            <em>(pre-1.6)<\/em>\n          <\/th>\n          <td>\n<code>true<\/code> (Boolean) Changed with checkbox state<\/td>\n        <\/tr>\n      <\/tbody><\/table>\n      <br>\n      <p>According to the <a href=\"https:\/\/www.w3.org\/TR\/html401\/interact\/forms.html#h-17.4\">W3C forms specification<\/a>, the <code>checked<\/code> attribute is a <em><a href=\"https:\/\/www.w3.org\/TR\/html4\/intro\/sgmltut.html#h-3.3.4.2\">boolean attribute<\/a><\/em>, which means the corresponding property is <strong>true<\/strong> if the attribute is present at all\u2014even if, for example, the attribute has no value or is set to empty string value or even \"false\". This is true of all boolean attributes.<\/p>\n      <p>Nevertheless, the most important concept to remember about the <code>checked<\/code> attribute is that it does not correspond to the <code>checked<\/code> property. The attribute actually corresponds to the <code>defaultChecked<\/code> property and should be used only to set the <em>initial<\/em> value of the checkbox. The <code>checked<\/code> attribute value does not change with the state of the checkbox, while the <code>checked<\/code> property does. Therefore, the cross-browser-compatible way to determine if a checkbox is checked is to use the property:<\/p>\n      <ul>\n        <li>\n          <code>if ( elem.checked )<\/code>\n        <\/li>\n        <li>\n          <code>if ( $( elem ).prop( \"checked\" ) )<\/code>\n        <\/li>\n        <li>\n          <code>if ( $( elem ).is( \":checked\" ) )<\/code>\n        <\/li>\n      <\/ul>\n      <p>The same is true for other dynamic attributes, such as <code>selected<\/code> and <code>value<\/code>.<\/p>\n    <\/div>\n<h3>Additional Notes:<\/h3>\n<div class=\"longdesc\"><ul><li>\n\t\t\tIn Internet Explorer prior to version 9, using <code><a href=\"\/prop\/\">.prop()<\/a><\/code> to set a DOM element property to anything other than a simple primitive value (number, string, or boolean) can cause memory leaks if the property is not removed (using <a href=\"\/removeProp\/\"><code>.removeProp()<\/code><\/a>) before the DOM element is removed from the document. To safely set values on DOM objects without memory leaks, use <a href=\"\/data\/\"><code>.data()<\/code><\/a>.\n\t\t<\/li><\/ul><\/div>\n<section class=\"entry-examples\" id=\"entry-examples\"><header><h2>Example:<\/h2><\/header><div class=\"entry-example\" id=\"example-0\">\n<p>Display the checked property and attribute of a checkbox as it changes.<\/p>\n<div class=\"syntaxhighlighter xml\">\n\t<table>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t\n\t\t\t\t<td class=\"gutter\">\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n1\">1<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n2\">2<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n3\">3<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n4\">4<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n5\">5<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n6\">6<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n7\">7<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n8\">8<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n9\">9<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n10\">10<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n11\">11<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n12\">12<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n13\">13<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n14\">14<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n15\">15<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n16\">16<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n17\">17<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n18\">18<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n19\">19<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n20\">20<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n21\">21<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n22\">22<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n23\">23<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n24\">24<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n25\">25<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n26\">26<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n27\">27<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n28\">28<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n29\">29<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n30\">30<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n31\">31<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n32\">32<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n33\">33<\/div>\n\t\t\t\t\t\n\t\t\t\t<\/td>\n\t\t\t\t\n\t\t\t\t<td class=\"code\">\n\t\t\t\t\t<pre><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-meta\">&lt;!doctype <span class=\"hljs-meta-keyword\">html<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">html<\/span> <span class=\"hljs-attr\">lang<\/span>=<span class=\"hljs-string\">\"en\"<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">head<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">meta<\/span> <span class=\"hljs-attr\">charset<\/span>=<span class=\"hljs-string\">\"utf-8\"<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">title<\/span>&gt;<\/span>prop demo<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">title<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">style<\/span>&gt;<\/span><span class=\"css\"><\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-selector-tag\">p<\/span> {<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>    <span class=\"hljs-attribute\">margin<\/span>: <span class=\"hljs-number\">20px<\/span> <span class=\"hljs-number\">0<\/span> <span class=\"hljs-number\">0<\/span>;<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  }<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-selector-tag\">b<\/span> {<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>    <span class=\"hljs-attribute\">color<\/span>: blue;<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  }<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">style<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">script<\/span> <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\">\"https:\/\/code.jquery.com\/jquery-4.0.0.js\"<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">script<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">head<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">body<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code> <\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"check1\"<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"checkbox\"<\/span> <span class=\"hljs-attr\">checked<\/span>=<span class=\"hljs-string\">\"checked\"<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">label<\/span> <span class=\"hljs-attr\">for<\/span>=<span class=\"hljs-string\">\"check1\"<\/span>&gt;<\/span>Check me<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">label<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code> <\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">script<\/span>&gt;<\/span><span class=\"javascript\"><\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>$( <span class=\"hljs-string\">\"input\"<\/span> ).on( <span class=\"hljs-string\">\"change\"<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-keyword\">var<\/span> $input = $( <span class=\"hljs-built_in\">this<\/span> );<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  $( <span class=\"hljs-string\">\"p\"<\/span> ).html(<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>    <span class=\"hljs-string\">\".attr( \\\"checked\\\" ): &lt;b&gt;\"<\/span> + $input.attr( <span class=\"hljs-string\">\"checked\"<\/span> ) + <span class=\"hljs-string\">\"&lt;\/b&gt;&lt;br&gt;\"<\/span> +<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>    <span class=\"hljs-string\">\".prop( \\\"checked\\\" ): &lt;b&gt;\"<\/span> + $input.prop( <span class=\"hljs-string\">\"checked\"<\/span> ) + <span class=\"hljs-string\">\"&lt;\/b&gt;&lt;br&gt;\"<\/span> +<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>    <span class=\"hljs-string\">\".is( \\\":checked\\\" ): &lt;b&gt;\"<\/span> + $input.is( <span class=\"hljs-string\">\":checked\"<\/span> ) + <span class=\"hljs-string\">\"&lt;\/b&gt;\"<\/span> );<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>} ).trigger( <span class=\"hljs-string\">\"change\"<\/span> );<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">script<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code> <\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">body<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">html<\/span>&gt;<\/span><\/code><\/div><\/div><\/pre>\n\t\t\t\t<\/td>\n\t\t\t<\/tr>\n\t\t<\/tbody>\n\t<\/table>\n<\/div>\n\n<h4>Demo:<\/h4>\n<div class=\"demo code-demo\"><\/div>\n<\/div><\/section>\n<\/div><\/article><article id=\"prop2\" class=\"entry method\"><h2 class=\"section-title\">\n<span class=\"name\">.prop( propertyName, value )<\/span><span class=\"returns\">Returns: <a href=\"http:\/\/api.jquery.com\/Types\/#jQuery\">jQuery<\/a><\/span>\n<\/h2>\n<div class=\"entry-wrapper\">\n<p class=\"desc\"><strong>Description: <\/strong>Set one or more properties for the set of matched elements.<\/p>\n<ul class=\"signatures\">\n<li class=\"signature\">\n<h4 class=\"name\">\n<span class=\"version-details\">version added: <a href=\"\/category\/version\/1.6\/\">1.6<\/a><\/span><a id=\"prop-propertyName-value\" href=\"#prop-propertyName-value\"><span class=\"icon-link\"><\/span>.prop( propertyName, value )<\/a>\n<\/h4>\n<ul>\n<li id=\"prop-propertyName-value-propertyName\">\n<div><strong>propertyName<\/strong><\/div>\n<div>Type: <a href=\"http:\/\/api.jquery.com\/Types\/#String\">String<\/a>\n<\/div>\n<div>The name of the property to set.<\/div>\n<\/li>\n<li id=\"prop-propertyName-value-value\">\n<div><strong>value<\/strong><\/div>\n<div>Type: <a href=\"http:\/\/api.jquery.com\/Types\/#Anything\">Anything<\/a>\n<\/div>\n<div>A value to set for the property.<\/div>\n<\/li>\n<\/ul>\n<\/li>\n<li class=\"signature\">\n<h4 class=\"name\">\n<span class=\"version-details\">version added: <a href=\"\/category\/version\/1.6\/\">1.6<\/a><\/span><a id=\"prop-properties\" href=\"#prop-properties\"><span class=\"icon-link\"><\/span>.prop( properties )<\/a>\n<\/h4>\n<ul><li id=\"prop-properties-properties\">\n<div><strong>properties<\/strong><\/div>\n<div>Type: <a href=\"http:\/\/api.jquery.com\/Types\/#PlainObject\">PlainObject<\/a>\n<\/div>\n<div>An object of property-value pairs to set.<\/div>\n<\/li><\/ul>\n<\/li>\n<li class=\"signature\">\n<h4 class=\"name\">\n<span class=\"version-details\">version added: <a href=\"\/category\/version\/1.6\/\">1.6<\/a><\/span><a id=\"prop-propertyName-function\" href=\"#prop-propertyName-function\"><span class=\"icon-link\"><\/span>.prop( propertyName, function )<\/a>\n<\/h4>\n<ul>\n<li id=\"prop-propertyName-function-propertyName\">\n<div><strong>propertyName<\/strong><\/div>\n<div>Type: <a href=\"http:\/\/api.jquery.com\/Types\/#String\">String<\/a>\n<\/div>\n<div>The name of the property to set.<\/div>\n<\/li>\n<li id=\"prop-propertyName-function-function\">\n<div><strong>function<\/strong><\/div>\n<div>Type: <a href=\"http:\/\/api.jquery.com\/Types\/#Function\">Function<\/a>( <a href=\"http:\/\/api.jquery.com\/Types\/#Integer\">Integer<\/a> index, <a href=\"http:\/\/api.jquery.com\/Types\/#Anything\">Anything<\/a> oldPropertyValue )\n\t\t\t=&gt;\n\t\t\t<a href=\"http:\/\/api.jquery.com\/Types\/#Anything\">Anything<\/a>\n<\/div>\n<div>A function returning the value to set. Receives the index position of the element in the set and the old property value as arguments. Within the function, the keyword <code>this<\/code> refers to the current element.<\/div>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div class=\"longdesc\" id=\"entry-longdesc-1\">\n      <p>The <code>.prop()<\/code> method is a convenient way to set the value of properties\u2014especially when setting multiple properties, using values returned by a function, or setting values on multiple elements at once. It should be used when setting <code>selectedIndex<\/code>, <code>tagName<\/code>, <code>nodeName<\/code>, <code>nodeType<\/code>, <code>ownerDocument<\/code>, <code>defaultChecked<\/code>, or <code>defaultSelected<\/code>. Since jQuery 1.6, these properties can no longer be set with the <code>.attr()<\/code> method. They do not have corresponding attributes and are only properties.<\/p>\n      <p>Properties generally affect the dynamic state of a DOM element without changing the serialized HTML attribute. Examples include the <code>value<\/code> property of input elements, the <code>disabled<\/code> property of inputs and buttons, or the <code>checked<\/code> property of a checkbox. The <code>.prop()<\/code> method should be used to set disabled and checked instead of the <code><a href=\"\/attr\/\">.attr()<\/a><\/code> method. The <code><a href=\"\/val\/\">.val()<\/a><\/code> method should be used for getting and setting value.<\/p>\n      <div class=\"syntaxhighlighter javascript\">\n\t<table>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t\n\t\t\t\t<td class=\"gutter\">\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n1\">1<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n2\">2<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n3\">3<\/div>\n\t\t\t\t\t\n\t\t\t\t<\/td>\n\t\t\t\t\n\t\t\t\t<td class=\"code\">\n\t\t\t\t\t<pre><div class=\"container\"><div class=\"line\"><code>$( <span class=\"hljs-string\">\"input\"<\/span> ).prop( <span class=\"hljs-string\">\"disabled\"<\/span>, <span class=\"hljs-literal\">false<\/span> );<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>$( <span class=\"hljs-string\">\"input\"<\/span> ).prop( <span class=\"hljs-string\">\"checked\"<\/span>, <span class=\"hljs-literal\">true<\/span> );<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>$( <span class=\"hljs-string\">\"input\"<\/span> ).val( <span class=\"hljs-string\">\"someValue\"<\/span> );<\/code><\/div><\/div><\/pre>\n\t\t\t\t<\/td>\n\t\t\t<\/tr>\n\t\t<\/tbody>\n\t<\/table>\n<\/div>\n\n      <p><strong>Important:<\/strong> the <code><a href=\"\/removeProp\/\">.removeProp()<\/a><\/code> method should not be used to remove native properties. This will lead to unexpected behavior. See <code><a href=\"\/removeProp\/\">.removeProp()<\/a><\/code> for more information.<\/p>\n      <h4 id=\"computed-prop-values\">Computed property values<\/h4>\n      <p>By using a function to set properties, you can compute the value based on other properties of the element. For example, to toggle all checkboxes based off their individual values:<\/p>\n      <div class=\"syntaxhighlighter javascript\">\n\t<table>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t\n\t\t\t\t<td class=\"gutter\">\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n1\">1<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n2\">2<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n3\">3<\/div>\n\t\t\t\t\t\n\t\t\t\t<\/td>\n\t\t\t\t\n\t\t\t\t<td class=\"code\">\n\t\t\t\t\t<pre><div class=\"container\"><div class=\"line\"><code>$( <span class=\"hljs-string\">\"input[type='checkbox']\"<\/span> ).prop( <span class=\"hljs-string\">\"checked\"<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"> i, val <\/span>) <\/span>{<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-keyword\">return<\/span> !val;<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>});<\/code><\/div><\/div><\/pre>\n\t\t\t\t<\/td>\n\t\t\t<\/tr>\n\t\t<\/tbody>\n\t<\/table>\n<\/div>\n\n      <p><strong>Note: <\/strong>If nothing is returned in the setter function (ie. <code>function( index, prop ){})<\/code>, or if <code>undefined<\/code> is returned, the current value is not changed. This is useful for selectively setting values only when certain criteria are met.<\/p>\n    <\/div>\n<h3>Additional Notes:<\/h3>\n<div class=\"longdesc\"><ul><li>\n\t\t\tIn Internet Explorer prior to version 9, using <code><a href=\"\/prop\/\">.prop()<\/a><\/code> to set a DOM element property to anything other than a simple primitive value (number, string, or boolean) can cause memory leaks if the property is not removed (using <a href=\"\/removeProp\/\"><code>.removeProp()<\/code><\/a>) before the DOM element is removed from the document. To safely set values on DOM objects without memory leaks, use <a href=\"\/data\/\"><code>.data()<\/code><\/a>.\n\t\t<\/li><\/ul><\/div>\n<section class=\"entry-examples\" id=\"entry-examples-1\"><header><h2>Example:<\/h2><\/header><div class=\"entry-example\" id=\"example-1-0\">\n<p>Disable all checkboxes on the page.<\/p>\n<div class=\"syntaxhighlighter xml\">\n\t<table>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t\n\t\t\t\t<td class=\"gutter\">\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n1\">1<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n2\">2<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n3\">3<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n4\">4<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n5\">5<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n6\">6<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n7\">7<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n8\">8<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n9\">9<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n10\">10<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n11\">11<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n12\">12<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n13\">13<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n14\">14<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n15\">15<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n16\">16<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n17\">17<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n18\">18<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n19\">19<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n20\">20<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n21\">21<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n22\">22<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n23\">23<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n24\">24<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n25\">25<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n26\">26<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n27\">27<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n28\">28<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n29\">29<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n30\">30<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n31\">31<\/div>\n\t\t\t\t\t\n\t\t\t\t<\/td>\n\t\t\t\t\n\t\t\t\t<td class=\"code\">\n\t\t\t\t\t<pre><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-meta\">&lt;!doctype <span class=\"hljs-meta-keyword\">html<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">html<\/span> <span class=\"hljs-attr\">lang<\/span>=<span class=\"hljs-string\">\"en\"<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">head<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">meta<\/span> <span class=\"hljs-attr\">charset<\/span>=<span class=\"hljs-string\">\"utf-8\"<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">title<\/span>&gt;<\/span>prop demo<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">title<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">style<\/span>&gt;<\/span><span class=\"css\"><\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-selector-tag\">img<\/span> {<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>    <span class=\"hljs-attribute\">padding<\/span>: <span class=\"hljs-number\">10px<\/span>;<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  }<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-selector-tag\">div<\/span> {<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>    <span class=\"hljs-attribute\">color<\/span>: red;<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>    <span class=\"hljs-attribute\">font-size<\/span>: <span class=\"hljs-number\">24px<\/span>;<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  }<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">style<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">script<\/span> <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\">\"https:\/\/code.jquery.com\/jquery-4.0.0.js\"<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">script<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">head<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">body<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code> <\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"checkbox\"<\/span> <span class=\"hljs-attr\">checked<\/span>=<span class=\"hljs-string\">\"checked\"<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"checkbox\"<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"checkbox\"<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"checkbox\"<\/span> <span class=\"hljs-attr\">checked<\/span>=<span class=\"hljs-string\">\"checked\"<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code> <\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">script<\/span>&gt;<\/span><span class=\"javascript\"><\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>$( <span class=\"hljs-string\">\"input[type='checkbox']\"<\/span> ).prop({<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-attr\">disabled<\/span>: <span class=\"hljs-literal\">true<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>});<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">script<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code> <\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">body<\/span>&gt;<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">html<\/span>&gt;<\/span><\/code><\/div><\/div><\/pre>\n\t\t\t\t<\/td>\n\t\t\t<\/tr>\n\t\t<\/tbody>\n\t<\/table>\n<\/div>\n\n<h4>Demo:<\/h4>\n<div class=\"demo code-demo\"><\/div>\n<\/div><\/section>\n<\/div><\/article>","protected":false},"excerpt":{"rendered":"<p>Get the value of a property for the first element in the set of matched elements or set one or more properties for every matched element.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,50,95],"tags":[],"class_list":["post-592","post","type-post","status-publish","format-standard","hentry","category-attributes","category-general-attributes","category-95"],"_links":{"self":[{"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/posts\/592","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/comments?post=592"}],"version-history":[{"count":4,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/posts\/592\/revisions"}],"predecessor-version":[{"id":1631,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/posts\/592\/revisions\/1631"}],"wp:attachment":[{"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/media?parent=592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/categories?post=592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/tags?post=592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}