What are the operation properties of jQuery
In this issue, the editor will bring you about the operational attributes of jQuery. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
1. Operation attribute 1. Read attribute value: attr (attribute name)
Gets the attribute value of the first matching element. This method makes it easy to get the value of an attribute from the first matching element. Returns undefined if the element does not have the corresponding attribute
2. Modify the attribute value (1) attr (key,value)
Set an attribute value for all matching elements
(2) attr (key,fn)
'key': represents the attribute name
'fn': represents a function and takes the attribute value of the function as the value of the attribute represented by key
Sets a calculated attribute value for all matching elements. Instead of providing a value, it provides a function with the value calculated by this function as the attribute value
(3) attr ({attribute name 1: attribute value, attribute name 2: attribute value}) 3. Delete attribute: removeAttr (attribute name)
Remove an attribute from each matching element
Document .ok {color: red;} go to Baidu
$(function () {let str = $('a') .attr ('href') / / Select the a tag to assign the attribute of href to str console.log (str) / / $('input'). Attr (' value','123') $('input'). Attr (' value',function () {/ / assign the value of the function to value, note that the function must have a return value of let s = 0; for (let item1