用Open Div替换HR元素

所以我已经被这一段时间困扰了一段时间,似乎无法绕过它。 我有一些通过wysiwyg编辑器添加的内容。 我想要做的是使用


元素在那里添加div来控制容器的外观。 问题是它添加了结束div。 我想将结束div添加到下一个hr元素。

 var firstChild = jQuery('.content-container-wrapper hr:first-child'); var lastChild = jQuery('.content-container-wrapper hr:last-child'); if (firstChild) { jQuery(firstChild).replaceWith('
'); };

有没有办法告诉浏览器不要添加结束div?

听起来你想要从第一个HR开始并以last结束。

以下将包装两个HR之间的所有内容,然后将其删除(我对您的问题的解释)。

 var $start=jQuery('.content-container-wrapper hr:first-child'), $end=jQuery('.content-container-wrapper hr:last-child'); $start.nextUntil( $end).wrapAll( '
'); $start.add($end).remove();

您不能插入元素的一部分,然后按照文本编辑器中的方式插入结尾

API参考:

http://api.jquery.com/wrapAll/

http://api.jquery.com/nextUntil/