views:

29

answers:

1

I have a variable i lifted the contents of, from a div on the page, like so:

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.

+1  A: 

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.

Felix Kling
Can i swap it out then instead of hiding the original, to maintain full functionality of css and all..
Doobox
Have a look at remove: http://api.jquery.com/remove/
Felix Kling