[Solved] Preserving .data() values when appending newly created element to parent window


It took me awhile (about a year – I forgot to come back and answer this when I first figured it out) to realise what was happening here and causing the problem I was having. I didn’t really have any understanding of how data was stored against DOM nodes when I asked the question, but I have a better (if not totally complete) idea of what’s occurring internally now when calling .data() to set and get values.

For DOM nodes jQuery has a global cache which it uses to store all of the data. Each node is then assigned a unique ID that acts as a key to later retrieve the data for that specific node from the cache.

That’s all relatively straightforward, so why doesn’t it work between browser windows? The answer is (now) quite obvious: each separate window has its own global cache, and the unique ID generated when setting the data in the child (popup) window doesn’t match an entry in the global cache for the parent window (if it even gets transferred at all).

solved Preserving .data() values when appending newly created element to parent window