【问题标题】:jQuery Move div into another divjQuery 将 div 移动到另一个 div
【发布时间】:2014-03-15 04:53:13
【问题描述】:

我需要将 .link-field-first-ticket-button 移到 .event-location-one 中

这是小提琴:http://jsfiddle.net/ksV73/

这是一个cms,所以我在这件事上别无选择。

这就是我正在尝试的,它没有做任何事情

$(".widget-upcoming-events-blog li").each( function() {
     var links = $(this).children(".link-field-first-ticket-button").html();
     $(this).children(".link-field-first-ticket-button").html("");
     $(this).children(".event-location-one").append(links);
});

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    你可以这样做:

    $(".link-field-first-ticket-button").appendTo(".event-location-one");
    

    它会将第一个票按钮移动到活动位置

    【讨论】:

    • 好看又简单,可爱
    • 真的很干净很简单!很好的答案。
    【解决方案2】:
    x = $(".widget-upcoming-events-blog").find(".link-field-first-ticket-button").remove()
    $(".event-location-one").append(x);
    

    【讨论】:

      【解决方案3】:

      html 方法将为您提供元素内部的内容,而不是元素本身。

      只需将元素附加到您想要的位置。由于一个元素不能同时存在于两个地方,所以它会被移动:

      $(".widget-upcoming-events-blog li").each( function() {
        var links = $(this).children(".link-field-first-ticket-button");
        $(this).children(".event-location-one").append(links);
      });
      

      【讨论】:

        【解决方案4】:

        试试这个

        $(".widget-upcoming-events-blog li").each( function() {
             var links = $(".link-field-first-ticket-button").html();
             $(".link-field-first-ticket-button").html("");
             $(".event-location-one").append(links);
        });
        

        【讨论】:

          【解决方案5】:

          将您的 .children() 更改为 .find()

          $(".widget-upcoming-events-blog li").each( function() {
               var links = $(this).find(".link-field-first-ticket-button").html();
               $(this).find(".link-field-first-ticket-button").html("");
               $(this).find(".event-location-one").append(links);
          });
          

          【讨论】:

            【解决方案6】:

            使用.appendTo()函数怎么样?

            例如:

            $(".widget-upcoming-events-blog li").each( function() {
             $(this).find(".link-field-first-ticket-button")
                    .appendTo( $(this).find(".event-location-one") );
            });
            

            【讨论】:

            • 伙计。你救了我的命:) 谢谢。其他方法出于某种原因在网站上复制了我的按钮,即使它们在小提琴上工作
            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2016-02-04
            • 2023-03-25
            • 2012-06-09
            • 2016-11-05
            • 1970-01-01
            • 2014-04-18
            相关资源
            最近更新 更多