Replace <span> element with var containing html
I have a variable i lifted the contents of, from a div on the page, like so:
开发者_JAVA技巧var originContents = $('#origin .teleportMe').html();
there is a set of span tags, with class="insertionPoint" on the page, i would like to remove and replace with the contents of the origin div.
i would prefer to do this with jquery but not essential.
replace this with the contents of: originContents
<span class="insertionPoint">insert</span>
Oh and hide the original after complete.
This should do it:
$('.insertionPoint').replaceWith(originContents);
$('#origin .teleportMe').hide();
See .replaceWith()
and .hide()
. But note that if the HTML contains elements with IDs and the HTML is now inserted into multiple places, using these IDs might lead to unexpected results.
精彩评论