How to update "complex" data stored with jQuery's .data()?
<p>It seems to me that jQuery's <code>.data()</code> function is more of a write-once store than true read-write-storage.</p>

<p>There does not seem to be a comfortable way of updating complex values.</p>

<p>Let's suppose one wants to use some elements in a double-linked list (not my use case, illustrative purpose only).</p>

<p>It would be easy if I would do:</p>

<pre><code>$elem.data('prev', $prev);
$elem.data('next', $next);
</code></pre>

<p>But I feel it is bad practice to pollute the "global" <code>.data()</code> namespace of an element.</p>

<p>So I would rather do:</p>

<pre><code>$elem.data('list', {prev: $prev, next: $next});
</code></pre>

<p>But how do I now update <code>prev</code>?</p>

<p>In the first example, I would just do:</p>

<pre><code>$elem.data('prev', $newPrev);
</code></pre>

<p>But in the in my opinion "nicer" way of doing things the only thing I can think of is something like this:</p>

<pre><code>$elem.data('list', {prev: $newPrev, next: $elem.data('list').next});
</code></pre>

<p>This seems a lot more cumbersome to me and I suspect there is a better way, but so far I was unable to find anything.</p>

<p>How should I go about this?</p>
