While going through the source, I noticed that ‘toggle’ supposedly uses jQuery._data to store the state of the element. I examined the jQuery.cache object in chrome and found that the element’s data object had yet another object under it prepended by the word jQuery with a number that I’m guessing uniquely identifies it. However, I saw no data regarding the state of the element. Simply {olddisplay: 'block'}. Any clues as to the purpose of jQuery._data and how it works per se?
I’ve been staring at the source all day …. please don’t tell me to view the source. My eyes and brain will thank you.
jQuery uses _data in order to set the ‘pvt’ flag for data it stores on the object. The
pvtis used so that when you request public data from the object, pvt data is not returned. This is to keep jQuery’s internal use of the.data()mechanism (like what toggle does) from effecting the public use of.data().You can see this declaration in the jQuery source:
Which just calls
jQuery.dataand forces the fourth parameter (which is privacy) to be true. When retrieving data, if thepvtflag is set, then it is retrieved in a slightly different way. The public interfaces to.data()do not expose thepvtflag.You can see an example of
pvthandling here in this part ofjQuery.data():and then later in that same function, this comment is pretty descriptive: