javascript - How to Drag and Drop multiple table cells in same table? -
i want drag , drop multiple cells table, code referring limited single cell operations. want perform same operation multiple cells. code using below:
table th,table td{ height: 30px; width: 200px; } table span{ display:block; background-color: #09c; height: 100%; width: 100%; }
<table id="#our_table" border="1"> <tr> <th>head1</th> <th>head1</th> <th>head1</th> </tr> <tr> <td><span class="event" id="a" draggable="true">aaa</span></td> <td></td> <td></td> </tr> </table>
$(document).ready(function(){ $('.event').on("dragstart", function (event) { var dt = event.originalevent.datatransfer; dt.setdata('text', $(this).attr('id')); }); $('table td').on("dragenter dragover drop", function (event) { event.preventdefault(); if (event.type === 'drop') { var data = event.originalevent.datatransfer.getdata('text',$(this).attr('id')); de = $('#'+data).detach(); de.appendto($(this)); }; }); })
this fiddle.
Comments
Post a Comment