JQuery: differences between attr () and prop ()

Source: Internet
Author: User
JQuery: differences between 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.
Obtains the attribute of the first element in the matched element set, or adds up to one attribute to each selected 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.
Obtains the property of the first element in the matched element set, or adds up to one property for each selected element.

It can be observed that the functions of the two are very similar, but the objects of the two operations are different.

In this way, the problem is reduced to the difference between attribute and property.

Attribute and propery both have the meaning of attributes. to distinguish them, we agree to name attribute as an attribute and property as a feature.


Attribute

In javascript, getAttribute () is used to obtain the node attribute values.

Node attribute value. We mean the value of src in

    

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.