How to combine two divs that have the same class - jQuery

后端 未结 5 1327
悲&欢浪女
悲&欢浪女 2020-12-11 09:24

I have a div structure like this

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-11 09:50

    For someone referring in future, a fixed and improved version of AdrianCooney 's answer:

    $.fn.combine = function(selector) {
     var parent = $(this[0]);
     this.each(function(i) {
        parent.append($(this).children(selector));
        if(i>0)
        $(this).remove();    
     });
    };
    

    You can call it like

    $(".itemRow").combine('.item');
    

    JSFiddle

提交回复
热议问题