These methods get and set DOM attributes of elements.
Get the value of an attribute for the first element in the set of matched elements.
It's important to note that the
.attr() method gets the attribute value for only the first element in the matched set. To get the value for each element individually, we need to rely on a looping construct such as jQuery's
Convenience: It can be called directly on a jQuery object and chained to other jQuery methods.
Cross-browser consistency: Some attributes have inconsistent naming from browser to browser. Furthermore, the values of some attributes are reported inconsistently across browsers, and even across versions of a single browser. The
.attr()method reduces such...