jQuery API
| attr | api.jquery.com/attr/#attr-attributeName |
| prop | api.jquery.com/prop/#prop-propertyName |
jQuery버전에 따른 차이
| jQuery버전 | attr | prop |
| 1.6 이전 | Attributes와 Properties를 구분하지 않음 | - |
| 1.6 이후 | Attributes (HTML의 속성) | Properties (DOM tree의 속성) |
<input type="checkbox" checked="">
위 체크박스에 대해서 아래와 같은 결과가 표시됨
| 상태 | 소스 | 결과 |
| 체크 | .attr("checked") | checked |
| .prop("checked") | true | |
| .is(":checked") | true | |
| 체크안함 | .attr("checked") | checked |
| .prop("checked") | false | |
| .attr("checked") | false |
<input type="checkbox">
위 체크박스에 대해서 아래와 같은 결과가 표시됨
| 상태 | 소스 | 결과 |
| 체크 | .attr("checked") | undefined |
| .prop("checked") | true | |
| .is(":checked") | true | |
| 체크안함 | .attr("checked") | undefined |
| .prop("checked") | false | |
| .attr("checked") | false |
'jQuery' 카테고리의 다른 글
| jquery-ui 타이틀바 지우기 (0) | 2021.03.02 |
|---|