Read July 17 of jquery (attribute/property/class)

Source: Internet
Author: User

Jquery's attribute module provides the following methods:

ATTR/removeattr

Prop/removeprop (1.6)

Addclass/removeclass/toggleclass/hasclass

Val

 

Several static methods are provided to support methods above the JQ object. For example, jquery. ATTR corresponds to ATTR, that is, the ATTR method of the JQ object internally calls jquery. ATTR. Second

Jquery. removeattr-> removeattr

Jquery. prop-> prop

 

ViewCodeIt can be found that jquery. Access is directly called in both the ATTR and prop methods.

 
ATTR: function (name, value) {return jquery. access (this, name, value, true, jquery. ATTR) ;}, prop: function (name, value) {return jquery. access (this, name, value, true, jquery. prop );},

 

The last parameter is jquery. ATTR and jquery. Prop. As you can imagine, this function will be called in jquery. Access. The following is the source code of jquery. Access.

 
Access: function (elems, key, value, exec, FN, pass) {var length = elems. length; // setting attributes attributesif (typeof key = "object") {for (var k in key) {jquery. access (elems, K, key [K], exec, FN, value);} return elems;} // setting one attributeif (value! = Undefined) {// optionally, function values get executed if exec is trueexec =! Pass & exec & jquery. isfunction (value); For (VAR I = 0; I <length; I ++) {fn (elems [I], key, exec? Value. Call (elems [I], I, FN (elems [I], key): value, pass) ;}return elems ;}// getting an attributereturn length? FN (elems [0], key): undefined ;},

 

When setting/retrieving attributes, traverse the jquery object and call the FN function in turn. The FN here may be jquery. ATTR and jquery. Prop.

Note that here we use for to traverse elems. This elems is actually a jquery object, which is an arraylike object.

 

This is probably the case. The remaining heap of hooks is used to solve the problem of browser compatibility. Such as jquery. attrhooks, jquery. prophooks, and jquery. valhooks. List as follows

1. IE6/7 does not fully support setattribute. For example, attributes such as class and for cannot be set.

2. getattribute in IE6/7 obtains the href/src attribute (relative path) value, which is different from other browsers.

3. There is a bug in obtaining the value of the button element in IE6/7.

4. IE6/7 does not support setattribute setting style/does not support getattribute obtaining style attribute values

5. The tabindex properties are different.

6. Repair of Boolean attributes, such as selected, disabled, and checked.

7. Fixed the values of select and option elements.

 

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.