The above example uses the jQuery Nestable plugin from dbushell . Do you have any control over the plugin that you end up using? The project is completely dead and has not been updated for 2 years.
It might be wise to check out a solution that is still supported, and offer your function, which is pretty much the "protectRoot" function that is currently available to many libraries.
If you do not have control over the plugin, this function is not currently implemented and probably will never be.
If you have control over the plugin but still want to use it, the solution may be to use a plug (there is a lot since the project is dead) is still supported and has this feature.
Another solution would be for the cherry to choose the code that interests you from the many migration requests submitted to the project, but it will never be merged.
For example, this pull request adds new callbacks instead of the only one available at the moment: beforeDragStart , dragStart , dragMove , beforeDragEnd , dragEnd , etc. These new callbacks contain many arguments, such as the item you are currently moving, where it was before you started dragging it, and the destination. Based on this new information and especially on the destination, you can cancel the drag and drop if the destination is the root of the node.
$('.dd').nestable({}) .on('dragMove', function(event, item, source, destination) {
Another transfer request that can meet your needs is this one . It provides a callback to reject a specific drag event, you can, for example, reject a drag event if the dragged item becomes the root item.
$('.dd').nestable({ reject: [ { rule: function() {