【发布时间】:2017-09-26 01:26:30
【问题描述】:
无法使其正常工作,因此它适用于每个帖子。
https://jsfiddle.net/haymanpl/htuczx5q/
<p>This is an example of a WordPress post, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many posts as you like in order to share with your readers what is on your mind.</p>
<div class="text">
<p>This is an example of a WordPress post, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many posts as you like in order to share with your readers what is on your mind.</p>
这是 WordPress 帖子的示例,您可以对其进行编辑以放置有关您自己或您的网站的信息,以便读者知道您来自哪里。您可以创建任意数量的帖子,以便与您的读者分享您的想法。
</div>
$( "p:first-child" ).after(function() {
return '<div class="text">';
});
这可行,但它添加了我不想要的结束 div 标签,因为我需要使用 last-child 添加它。
$('p:first-child').after( $('<div class="text">') );
我正在尝试将多个段落包装在一个 div 中,不包括第一个。我需要在第一段之后插入,然后在最后一段之后插入结尾。
【问题讨论】:
-
您不能插入部分或未闭合的标签。
-
你是什么意思“我不想要因为我需要使用 last-child 添加它”?您是否尝试将一个或多个元素包装在
span中?如果是这样,请更新您的问题。 -
你看看
.wrap的 jquery -
您的标题询问了 div,但您的代码提到了跨度。是哪一个?
-
span 是段落内元素,因此您不应将 p 包装在 span 标签内。 (w3.org/TR/html5/dom.html#phrasing-content-1)。您可以通过将它们包装在 div 中来做您需要的事情。你需要做什么?
标签: jquery html css insertafter