开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜