Given jQuery's philosophy of write less, do more, I'm always surprised when I see this:
$(this).prop('checked')
… instead of this:
this.checked
Looking at the latest jQuery source, prop()
provides convenience for these two gotchas:
$(elem).prop('for')
is equivalent toelem.htmlFor
.$(elem).prop('class')
is equivalent toelem.className
.
It also normalizes tabIndex
to:
- 0 for tabbable elements without a tab index.
- -1 for non-tabbable elements.
prop()
is certainly useful for setting properties for multiple elements at once, and for chaining properties on a single element.
But is there any advantage (other than idiomatic) to use prop()
to set or retrieve a single property on a single element except when normalizing tabIndex
– specifically when you have a reference to the element (such as this
in a callback)?