I’m doing fancy ajaxy dhtml stuff with caching. After I ajax-download a page of interest, I store the contents in an array of variables
HistoryCache[url].load(url, handleRSX);
(this part works fine)
Afterwards I perform a link-fixer:
$('a', HistoryCache[url]).click(...)
Where ... is the code that converts a normal link to my ajaxy calling.
After all this is done I need to .append() my new content to a div that’s specifically made to hold the new stuff. Prior to appending I .remove() whatever contents were there before.
Problem: When the requested URL is in my HistoryCache I do not .load() it, and I do not fix the links via .click(). I simply take the contents in the cache and put it in my holder. At this point the links are not fixed, and actually change the browser to the intended link rather than calling my function.
Question: Why does the .click() not remain in the stored cache array after its been .removed() and re .append()ed?
Forgot to mention that I have resolved this by changing my click override to the native HTML’s this.onclick = function... instead of $(this).click(function(){});
On .remove() all attached jQuery events are intentionally removed to prevent memory leaks. If this weren’t done jQuery would leak memory in a bad way.
To work around this with jQuery you can use .live() or .delegate(). Both work by propagating events further up the DOM than your bound element (the document in the case of live and the element specified in the case of delegate) and will work after remove and add.