Jquery 附加项位于已存在项下

Jquery 附加项位于已存在项下,jquery,Jquery,我试图在同位素中添加内容,这是可行的,但新内容放在已经存在的项目下,而不是在它们之后 以下是我的JQuery代码: $('#og-grid').isotope({ itemSelector : 'li' }); $('#sort-by a').click(function(){ var selector = $(this).attr('data-filter'); $('#og-grid').isotope({ filter: selector });

我试图在同位素中添加内容,这是可行的,但新内容放在已经存在的项目下,而不是在它们之后

以下是我的JQuery代码:

  $('#og-grid').isotope({
    itemSelector : 'li'
  });

  $('#sort-by a').click(function(){
    var selector = $(this).attr('data-filter');
    $('#og-grid').isotope({ filter: selector });
    $('#og-grid').isotope( 'reLayout' );
    return false;
  });

  $('a#plus_projet').click(function(){
    var appendContent = $('.portfolio_projects_hide ul').html();
    $('.portfolio_projects ul').append(appendContent).isotope('appended', appendContent);
    $('#og-grid').isotope( 'reLayout' );
    return false;
  });

同位素需要一个jQuery集合作为第二个参数

虽然内容已正确更新,但在附加到容器时使用jQuery集合也会有所不同

尝试:


你能提供你的HTML的一个例子吗?这将有助于找出问题所在。插入函数工作得更好。但是项目被添加了两次,第一次是在已经存在的项目下,第二次是在使用同位素样式'class=“同位素项目”style=“位置:绝对;左侧:0px;顶部:0px;不透明度:1;转换:translate3d(438px,1184px,0px)scale3d(1,1,1);”>'为什么要添加两次?@MaudeLavoie在附加到容器时,似乎有必要使用jQuery集合,而不仅仅是HTML字符串。我已经更新了答案,并提供了一个提琴来显示它与该更改一起工作。
$('a#plus_projet').click(function(){
    var appendContent  = $('.portfolio_projects_hide ul').html();

    // Use this variable to append
    var $appendContent = $(appendContent);

    $('.portfolio_projects ul').append($appendContent).isotope('appended', $appendContent);

    // Not necessary when appending items...
    $('#og-grid').isotope('reLayout');
    return false;
});