I found a great solution (last answer):
jQuery Sortable - select and drag multiple list items
http://jsfiddle.net/hQnWG/480/
HTML:
<ul> <li>One</li> <li>Two</li> <li>Three</li> </ul> <ul> <li>Four</li> <li>Five</li> <li>Six</li> </ul>
JavaScript (with jQuery and jQuery UI):
$("ul").on('click', 'li', function (e) { if (e.ctrlKey || e.metaKey) { $(this).toggleClass("selected"); } else { $(this).addClass("selected").siblings().removeClass('selected'); } }).sortable({ connectWith: "ul", delay: 150, //Needed to prevent accidental drag when trying to select revert: 0, helper: function (e, item) { var helper = $('<li/>'); if (!item.hasClass('selected')) { item.addClass('selected').siblings().removeClass('selected'); } var elements = item.parent().children('.selected').clone(); item.data('multidrag', elements).siblings('.selected').remove(); return helper.append(elements); }, stop: function (e, info) { info.item.after(info.item.data('multidrag')).remove(); } });
It works fine, but when I drag two or more elements, the JS console in Google Chrome shows this error:
Uncaught TypeError: cannot call 'insertBefore' method from null
How to fix it?
source share