javascript - Select only those elements which has changed there positions after sorting by .sortable -
i have 5 divs . ordered per priority.i sorting there positions using jquery sortable. there way know position of divs has changed there position during sorting.
html section:
<body> <div id="sortable"> <?php foreach($data $row){ ?> <div class="alert alert-success" data-id="<?php echo $row['id'] ?>" role="alert"><?php echo $row['div-name']; ?></div> <?php } ?> </div> </body> sctript part: <script> $( function() { var lastmoved = null; $("#sortable div").mousedown(function(){ lastmoved = this; }); $("#sortable").sortable({ start: function(e, ui) { //alert(""); // console.log("prev: "+$(this).attr('data-id')); }, update: function(event, ui) { alert("moving: "+$(lastmoved).attr("data-id")); alert("moved to: "+parseint($(lastmoved).index()+1)); }, stop: function(event, ui) { var data = ""; $("#sortable div").each(function(i, el){ var p = $(el).attr("data-id").tolowercase().replace(" ", "_"); data += p+"="+parseint($(el).index()+1)+","; }); console.log(data.slice(0, -1)); } }); } ); </script>
Comments
Post a Comment