Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use data () of jquery

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article editor for you to introduce in detail "jquery data () how to use", the content is detailed, the steps are clear, the details are handled properly, I hope this "jquery data () how to use" article can help you solve your doubts, the following follow the editor's ideas slowly in-depth, together to learn new knowledge.

In jquery, the data () method can be used to attach data to the selected element with the syntax "$(selector) .data (name,value)" or to get data from the selected element with the syntax "$(selector) .data (name)".

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

Jquery data () method

The data () method appends data to or gets data from the selected element.

Syntax:

Returns additional data from the selected element.

The $(selector) .data (name) parameter describes the name

Optional. Specifies the name of the data to be retrieved.

If no name is specified, the method returns all stored data from the element as an object.

Attach data to the selected element.

Can be a single name / value pair

The $(selector) .data (name,value) parameter describes the name required. Specifies the name of the data to be set. Value is required. Specifies the value of the data to be set.

You can also use objects with name / value pairs to add data to the selected element.

The $(selector) .data (object) parameter describes the object required. Specifies the object that contains the name / value pair.

Example: attach data to an element and then retrieve that data

$(document) .ready (function () {$("# btn1") .click (function () {$("div") .data ("greeting", "Hello World");}) $("# btn2") .click (function () {alert ($("div"). Data ("greeting");});}) Add data to the div element to get the data that has been added to the div element

After reading this, the article "how to use data () of jquery" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report