用Open Div替换HR元素 [英] Replace HR Element with Open Div
问题描述
所以我已经被这一段时间困扰了一段时间并且似乎无法绕过它。我有一些通过wysiwyg编辑器添加的内容。我想要做的是使用< hr>
元素在其中添加div来控制容器的外观。问题是它添加了结束div。我想将结束div添加到下一个hr元素。
So I have been stumped with this for a while now and can't really seem to get around it. I have some content that is added through a wysiwyg editor. What I want to do is use the <hr>
element to add divs in there to control the look of the container. The problem is that it adds the closing div. I want to add the closing div to the next hr element.
var firstChild = jQuery('.content-container-wrapper hr:first-child');
var lastChild = jQuery('.content-container-wrapper hr:last-child');
if (firstChild) {
jQuery(firstChild).replaceWith('<div class="working">');
};
有没有办法告诉浏览器不要添加结束div?
Is there a way to tell the browser not to add the closing div?
推荐答案
听起来你想要包装从第一个HR开始到最后一个结束的所有内容。
It sounds like you want to wrap everything starting with the first HR and ending with last.
以下将在两个HR之间包装所有内容然后删除它们(我对你的问题的解释)。
Following will wrap everything between the two HR and then remove them( my interpretation of your question).
var $start=jQuery('.content-container-wrapper hr:first-child'),
$end=jQuery('.content-container-wrapper hr:last-child');
$start.nextUntil( $end).wrapAll( '<div class="working">');
$start.add($end).remove();
您不能插入元素的一部分,然后像在文本中那样插入结尾编辑
You can't insert part of an element and then insert the end the way you do in a text editor
API参考:
http://api.jquery.com/wrapAll/
http://api.jquery.com/nextUntil/
这篇关于用Open Div替换HR元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!