I have an html node and another one just like it in structure with minor differences. (both are very complex nodes) both nodes have a lot of jQuery.data set on their children. One node is in the document and the other is just a fragment in the memory.
I want to replace the content of the node in the DOM with the fragment one, and preserve all the jQuery.data along with the fragment, but it just get lost using html()..how can I preserve it?
Avoid using
.html(), use something like.replaceWith()instead. This will move the DOM elements around, rather than plainly overwriting the textual HTML