I want to drag and sort div elements by Jquery. Here I want to drag and sort div item as I want.
Please see my code:
<div id="short" class="connected-sortable area">
<div class="curve c2">
<p class="cat">
<a href="car.html">
<img src="images/car.png" height="30" alt="" style="margin-bottom: 9px"> Car
</a>
</p>
</div>
<div class="curve c3">
<p class="cat">
<a href="bus.html">
<img src="images/bus.png" height="30" alt="" style="margin-bottom: 9px"> Bus
</a>
</p>
</div>
<div class="curve c4">
<p class="cat">
<a href="apartment.html">
<img src="images/apt.png" height="30" alt="" style="margin-bottom: 9px"> Apartment/House
</a>
</p>
</div>
<div class="curve c5">
<p class="cat">
<a href="hotel.html">
<img src="images/hotel.png" height="30" alt="" style="margin-bottom: 9px"> Hotel/Room
</a>
</p>
</div>
<div class="collapse" id="catshow">
<div class="curve c6">
<p class="cat">
<a href="hotel.html">
<img src="images/helicopter.png" height="30" alt="" style="margin-bottom: 9px"> Helicopter
</a>
</p>
</div>
<div class="curve c7">
<p class="cat">
<a href="hotel.html">
<img src="images/plane.png" height="30" alt="" style="margin-bottom: 9px"> Chartered Plane
</a>
</p>
</div>
<div class="curve c8">
<p class="cat">
<a href="hotel.html">
<img src="images/yacht.png" height="30" alt="" style="margin-bottom: 9px"> Yacht & Boat
</a>
</p>
</div>
</div>
</div>
<div class="text-center">
<button class="btn btn-show-hide" type="button" data-toggle="collapse" data-target="#catshow" aria-expanded="false" aria-controls="catshow">
Show more/less
</button>
</div>
script:
function renumber() {
var count = 1;
$('#short .curve').each(function () {
$(this).find('.cat').text(count);
count++;
});
}
function init() {
$( ".area" ).sortable({
connectWith: ".connected-sortable",
stack: '.connected-sortable'
}).disableSelection();
}
$( init );
$( ".connected-sortable" ).on( "sortupdate", function( event, ui ) {
renumber();
} );
Here I want to drag the .curve div so that I can sort the .curve div item. Suppose I want to move Bus first, Aparment/house second etc. Can you please help me to correct my code or write a better code for this.