jQuery has clean and cleanData methods. What is the purpose of jQuery clean and cleanData methods?
From "Secrets of the Javascript Ninja"
<script type="text/javascript">
function clone() {
var ret = this.map(function () {
if (!jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this)) {
var clone = this.cloneNode(true),
container = document.createElement("div");
container.appendChild(clone);
return jQuery.clean([container.innerHTML])[0];
}
else
return this.cloneNode(true);
});
var clone = ret.find("*").andSelf().each(function () {
if (this[ expando ] !== undefined)
this[ expando ] = null;
});
return ret;
}
</script>
"... the preceding code uses JQuery's Jquery.clean method, which converts an HTML string into a DOM structure"
Both are internal, undocumented methods, so you should not use them or rely on their current behavior, because they might change or disappear in the future.
That said, clean()
sanitizes the markup in the document fragments that are created from the HTML strings passed to some functions (most notably to $() itself).
cleanData()
frees the data associated with elements when they disappear from the DOM, e.g. through remove(), empty(), or html().