title: jquery, attaching objects (instead of string attribute) to an element
body: <p>I'm trying to build DOM with jQuery and fill it with data that is received with AJAX (data type = json). I'd like to also store this data as an object, attached to a specific DOM element. Does jQuery provide any method for this? The reason I want to do it is because only part of data is initially displayed; other data might be needed later, depending on user actions.</p>
  
  <p>I tried using <code>attr()</code>, but it stores a string "[object Object]" instead of an actual object:</p>
  
  <pre><code>var div = $('&lt;div/&gt;');
  div.attr('foo', {bar: 'foobar'});
  alert(div.attr('foo')); // gives "[object Object]"
  alert(typeof div.attr('foo')); // gives "string"
  alert(div.attr('foo').bar); // gives "undefined"
  </code></pre>
  
  <p>Another way to do this would be by "bypassing" jQuery (<code>div[0].foo = {bar: 'foobar'};</code>), though this seems to be a "dirty workaround", if jQuery happens to already support attaching objects.</p>
  
  <p>Any ideas? Thanks in advance!</p>