In jQuery, you have to be careful to use .attr() and .prop().
.attr() Get the value of an attribute for the first element in the set of matched elements or set one or more attributes for every matched element.
.prop() 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.
They are very similar, but not exactly same.
The difference between attributes and properties can be important in specific situations. Before jQuery 1.6, the .attr() method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior. As of jQuery 1.6, the
.prop() method provides a way to explicitly retrieve property values, while
defaultSelectedshould be retrieved and set with the
.prop() method. Prior to jQuery 1.6, these properties were retrievable with the
.attr()method, but this was not within the scope of
attr. These do not have corresponding attributes and are only properties.