Kieran Barker14,976 Points
.prop() vs .attr()
Why does Dave use jQuery's
.prop()method in one instance, and then
.attr()in another to accomplish the same thing? What's the difference? Surely it would be better to be consistent?
Why does setting
.attr("disabled", false)work? My understanding was that the mere presence of the
disabledattribute turns it on, so
disabled="sandwich"would all make something disabled. I thought you had to actually remove the attribute altogether. Or is this how jQuery handles it in this case, specifically?
I had the same question and did not find the jQuery docs very useful in answering it. I found several discussions of how properties and attributes are different, but what helped me understand it was to realize that in the first case of
$searchField.prop("disabled", true) we are setting the property of that field to be disabled. In the second case,
$submitButton.attr("disabled", true).val("searching ..."); we are disabling the submit button AND we are changing the value attribute from "Search" to "searching ...". Hope that is helpful.