代码片段 → jQuery代码片段 → 在其他元素之间插入元素 在其他元素之间插入元素 Chris Coyier 于 2010年2月16日 例如,如果您连续有五个段落,并且需要在它们之间插入一个换行标签。您不能将其放在所有五个段落之前(顶部不需要),也不能放在所有五个段落之后(底部不需要),您只需要四个。 $("p:not(:last-of-type)").after("<br />");
这也可以工作..
$("p:not(:first-of-type)").before("");
引号之间应该有一个换行标签。
:first-of-type不是选择器过滤器,因此sinppent不起作用。
以下是更正
$('.parent_of_target_p_tags').children('p.not(:last-child)').after('');
根据我的CSS袖珍参考书,“:first-of-type”确实是一个选择器过滤器。