1 回答
TA贡献1790条经验 获得超9个赞
用于.each()单独处理每个元素,仅附加到前一个元素。
$(document).ready(function() {
$('.bdt-post-grid-category').wrapInner('<span class="bdt-post-grid-date cat"></span>');
$('.bdt-post-grid-date.cat').each(function() {
$(this).appendTo($(this).closest(".bdt-post-grid-category").prev());
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="bdt-post-grid-meta bdt-subnav bdt-flex-middle">
<span class="bdt-post-grid-date">date</span>
</div>
<div class="bdt-post-grid-category bdt-position-small bdt-position-top-left">
<a href="#" rel="category tag">category</a>
</div>
<div class="bdt-post-grid-meta bdt-subnav bdt-flex-middle">
<span class="bdt-post-grid-date">date</span>
</div>
<div class="bdt-post-grid-category bdt-position-small bdt-position-top-left">
<a href="#" rel="category tag">category2</a>
</div>
<div class="bdt-post-grid-meta bdt-subnav bdt-flex-middle">
<span class="bdt-post-grid-date">date</span>
</div>
<div class="bdt-post-grid-category bdt-position-small bdt-position-top-left">
<a href="#" rel="category tag">category3</a>
</div>
- 1 回答
- 0 关注
- 72 浏览
添加回答
举报