Operations element attributes and features of jQuery Learning

Source: Internet
Author: User

Property: a property in a DOM element that corresponds to a property in an HTML element.

The methods provided in jQuery are listed below:

Operation element attribute: each (iterator) traverses all elements in the package and calls the passed iterator functions for each element. The iterator parameter is a function that is called once for each element in the matching set. The parameter passed to the function is set to the subscript of the current element in the package set (starting from 0), and the current element can be accessed through the this attribute of the function.

$ ('Img '). each (function (n ){

This. alt = 'this is image ['+ n +'] with an id of '+ This. id;

})

Get feature value: attr (name) gets the value of the specified feature assigned to the first element in the package. The parameter name is the name of the feature. The value of this feature is obtained. If this feature is not available, the undefined value is returned.

$ ("# MyImage"). attr ("custom") returns some value.

Set feature value: attr (name, value) sets the passed value for the name feature of all elements in the package. Name indicates the name of the feature to be set. value indicates the value of the feature.

$ ('*'). Attr ('title', function (index ){

Return 'I am element ''+ index +' and my name is '+ (this. id? This. id: 'unset ');

});

This function sets the title attribute of all elements on the page as a string. A string consisting of the subscript of the element in the DOM and the id feature value of each specific element.

Attr () also allows you to set multiple features at a time to a quick and easy way for all elements in the package. Attr (attributes ).

$ ('Input'). attr (

{Value: '', title: 'Please enter a value '}

);

This function sets the value of all <input> elements to an empty string and the title to the string Please enter a value.

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.