Posted By

1man on 11/13/08


Tagged

data jquery store


Versions (?)

Who likes this?

7 people have marked this snippet as a favorite

VaiT
jamesming
ntulip
bryandease
gtalmes
alejandrosuch
seanpowell


The jQuery Data Store


 / Published in: JavaScript
 

I didn't realise until now you could do this in jQuery, very useful. Store a value for later use, then remove it.

  1. //Store a color
  2. $(this).data('color', $(this).css('color'));
  3. //Retrieve the color later
  4. $(this).css('color', $(this).data('color'));
  5. //Remove the data
  6. $(this).removeData('color');

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: VaiT on November 13, 2008

Oh that's awesome, i didn't know that ingenious ability. Thanks alot =)

Posted By: RambleCampbell on March 26, 2009

Does anyone know exactly how this mechanism works? I assumed it was adding custom attributes to the element, but I don't see that in Firefox, which typically shows that kind of thing. Is it simply stored in browser memory? I'm curious about exactly how it works, so I know the limitations. Thanks.

You need to login to post a comment.