【问题标题】:I'd like to change the order of HTML elements inside a section我想更改部分内 HTML 元素的顺序
【发布时间】:2016-06-07 11:33:28
【问题描述】:

这基本上是我的 woocommerce 产品的样子:

<section class="mpcth-post-content">
    <div class="mpcth-cart-wrap">
    <h6 class="mpcth-post-title"></h6>
</section>

我想要的只是将顺序更改为 section->title->wrap.

我尝试用 jQuery 改变它:

$(document).ready(function() {
    $('.mpcth-post-title').insertBefore('.mpcth-cart-wrap')
});

但是它将每个产品的标题从页面上显示的每个部分放置到每个产品。

我也想知道是否可以使用儿童主题功能来完成? 基础 php 来自一个框架mpc_visual_composer.php

【问题讨论】:

    标签: jquery wordpress dom woocommerce prepend


    【解决方案1】:

    您选择的行为是正常的。你想要做的是insertBefore 在每个部分的上下文中。使用子选择器和循环。

    $('.mpcth-post-content').each(function(){
        $(this).find('.mpcth-post-title').insertBefore($(this).find('.mpcth-cart-wrap'));
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-07
      • 1970-01-01
      • 2021-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多