The example in this article describes the usage of the data() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:
This method can append data to the matching element, or get data from the matching element.
Grammar structure 1:
Parameter list:
Example code:
The above code can append the name mydata to the matching div element, the value is "Script Home Welcomes You" data, and then use the data name to return.
Grammar structure 2:
Returns additional data with the specified data name from the matching element.
Parameter list:
Example code:
The above code can append the name mydata to the matching div element, the value is "Script Home Welcomes You" data, and then use the data name to return.
Grammar structure three:
Add data to matching elements using key/value pair objects.
Parameter list:
Example code:
The above code can append data named mydata to the div in the form of key/value pairs, and then obtain the attached data value through the data name and key.
Grammar structure four:
Use object method to append data to the specified element.
Parameter list:
Example code:
The above code appends data in the form of objects and obtains the attached data value.
I hope this article will be helpful to everyone’s jQuery programming.