How do you use jQuery .data() to store html?

Posted by Al on Stack Overflow See other posts from Stack Overflow or by Al
Published on 2010-04-04T00:39:29Z Indexed on 2010/04/04 0:43 UTC
Read the original article Hit count: 242

Filed under:

Hi all - when I look up the syntax for .data(), it gives examples like this:

$('body').data('foo', 52);

I am doing AJAX loads and I was wondering if it is possible to store the incoming html using .data() so once the content is loaded, I would not need to do another AJAX load if the same link is clicked again - I would check to see if the .data key is empty.

Would something like this work?:

To load the contents of a #ajaxdiv into storage:

$('body').data('storage', div#ajaxdiv.html());

To test if the data has already been loaded:

if $('body').data('storage') != '' {

div#ajaxdiv.html($('body').data('storage'));

}

Thanks in advance!!

Al

© Stack Overflow or respective owner

Related posts about jQuery