Jquery.data () data cache

Source: Internet
Author: User

The difference between $ (""). Data ([Key],[value]) and $.data (Element,[key],[value]):


$.data (Element,[key],[value]) adds cached data to element in a way that distinguishes between two forms of object: JS object, Dom element.

1. If you add cached data for a JS object, jquery encapsulates the cached data in a new object and assigns the new object to a specific attribute of the JS object above (for example: jQuery164007486486807465553). This means that the cached data is eventually stored in the JS object itself.

2. If you are adding cached data for DOM elements, jquery will also encapsulate the cached data in a new object, but place the new object in a global cache and place the index in the DOM element. When you want to get the cached data, simply use this index to find the appropriate object in the cache.


and $ (""). Data ([Key],[value]) is specifically used to add caches for the DOM elements selected by the jquery selector, or to add cached data specifically for DOM elements. We know that the result of the jquery selector is a collection, $ (""). Data ([Key],[value]) assigns the cached data to each element of the collection, and he first converts the elements in the collection from the JQuery object form to the normal DOM object, and then calls the $.data (Element,[key],[value]).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.