Better not to use html() .
I ran into some problems due to html interpreting the content as a string instead of a DOM node.
Use the content instead, and other scripts should not be interrupted due to broken links.
I needed to embed the contents of the DIV in myself, thatβs how I did it.
Example:
<div id="xy"> <span>contents</span> </div> <script> contents = $("#xy").contents(); </script>
[EDIT]
The previous example works, but here's a cleaner and more efficient example:
<script> var content = $("#xy").contents(); //find element var wrapper = $('<div style="border: 1px solid #000;"/>'); //create wrapper element content.after(wrapper); //insert wrapper after found element wrapper.append(content); //move element into wrapper </script>
Dieter gribnitz
source share