The jQuery Data Store


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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

You need to login to post a comment.