What is the difference between attr() and prop() in jQuery?
<input type="checkbox" id="c" checked>
$('#c').prop('checked', false);
console.log('prop: ' + $('#c').prop('checked'));
console.log('is checked: ' + $('#c').is(':checked'));
Console output
prop: false
is checked: false
The property shows the live state (false now), while the attribute in the HTML is the starting value. In jQuery 4, attr('checked') also returns a different value than in 3.x, so always use prop(). See Get Content.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |