Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jquery

I have a div structure like this

<div class="items">
    <div class="itemRow">
        <div class="item">
        <div class="item">
        <div class="item">
    </div>
    <div class="itemRow">
        <div class="item">
        <div class="item">
        <div class="item">
    </div>
</div>

How can I make them merge/combine the two divs "itemRow"? to be like this

<div class="items">
    <div class="itemRow">
        <div class="item">
        <div class="item">
        <div class="item">
        <div class="item">
        <div class="item">
        <div class="item">
    </div>
</div>

using jQuery

like image 435
Ryan Barnaby Avatar asked Dec 16 '22 06:12

Ryan Barnaby


1 Answers

Try

var $rows = $('.items .itemRow');
$rows.first().append($rows.not(':first').children())
$rows.not(':first').remove();

Demo: Fiddle

like image 85
Arun P Johny Avatar answered Jan 17 '23 07:01

Arun P Johny