Where is jQuery.data() stored?

qwertymk picture qwertymk · Apr 28, 2011 · Viewed 9.7k times · Source

Where does jQuery store the values of the data() that it sets to DOM objects?

Is there some kind of variable like jQuery.dataDb or something, maybe even something private?

Is there any way to gain access to this object?

Answer

KushalP picture KushalP · Apr 28, 2011

Internally, jQuery creates an empty object called $.cache, which is used to store the values you set via the data method. Each DOM element you add data to, is assigned a unique ID which is used as a key in the $.cache object.