Search code examples
jquery-uijquery-ui-droppable

Jquery ui droppable exclude the particular division


Ex:

<div class="droppable">
     <div class="except_this_div"></div>
</div >

I have a jquery ui droppable event for the above example in which the drop should not happen for

$('.droppable').droppable({});

I need to exclude the droppable only for <div class="except_this_div"></div>


Solution

  • You can accomplish this by using the jquery ui draggable revert function.

    HTML

    <div class="droppable">
      <div class="except_this_div"></div>
    </div>
    <div class="draggable">
    

    JQuery

    var revert;
    
    $('.droppable').droppable({  
                drop: function( event, ui ){
                revert = false;
            }
    });
    
    $('.except_this_div').droppable({
      greedy: true
    });
    
    $('.draggable').draggable({
      revert: function(){
        return revert;
      },
      start: function(){
        revert = true;  
      }
    });
    

    Fiddle:

    https://jsfiddle.net/qL0tb12h/2/