Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the operation properties of jQuery

Shulou Source: shulou.com Published: 2022-06-02 03:05:28 09月30日 Update

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

Tags: Attributes elements styles functions content universities posts and telecommunications Xi'an discoloration width color analysis output professional small and medium representative rich content objects that is tools Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Redmi Docker Microsoft OPPO Reno