0

I'm learning that using

replaceWith('<section>')

or

after('<section>')

Will actually insert the full element in each case:

<section></section>

And that when using end tags

replaceWith('</section>')

such calls seem to be ignored.

Is there someway to disable this behavior? I need to at one point in the DOM insert a start tag, and at another point insert an end tag.

wrapAll() 

I can't get to work either. I think probably something to do with what is being wrapped aren't all siblings.....

4

1 回答 1

0

我不相信 jquery 会允许这种行为,因为这实际上会允许你使你的标记无效。

处理 dom - 它将这些标签组视为“节点”。它们被组合为具有属性和值的对象以及依赖于它们的许多其他对象。所以简单地“移动结束标签的文本”并不是想要的效果......

为什么不在半标签的“中间”抓住所有你想要的东西......创建一个新元素,然后用追加将你的“填充”放入其中?像这样的东西:

var theFilling = $('ul#theFilling'),
    theCookieCrust = document.createElement('section');

$(theFilling).appendTo($(theCookieCrust));

$('ul#theFilling').remove();

$(theCookieCrust).appendTo('body');
于 2013-10-22T21:32:39.500 回答