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.