Cannot re-enable droppable after disabling it

Cannot re-enable droppable after disabling it

I want to make draggable divs which can be dragged into empty parent divs. Each parent can only accept one draggable. To do this, I disable the droppable after the draggable has been dropped. However, when I move the draggable from the droppable, trying to re-enable it crashes my script.

In the code below, I should be able to drag the grey boxes into a green box. When dragging, the previous box should turn green and then accept another grey box.

The code below has the offending command commented out.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>$(document).ready(function () {
$(".draggable").draggable({
start: function(event, ui){
// Line below causes a script error
// $(this).parent().droppable('enable');
},
revert: "invalid",
helper: "original",
zIndex: 100
});
$(".accept").droppable({
accept: ".draggable",
drop: function (event, ui) {
$(this).append(ui.helper);
$(this).droppable('disable');
ui.draggable.position({
of: $(this),
my: 'left+1 top+1',
at: 'left top'
});
}
});
});</code>
<code>$(document).ready(function () { $(".draggable").draggable({ start: function(event, ui){ // Line below causes a script error // $(this).parent().droppable('enable'); }, revert: "invalid", helper: "original", zIndex: 100 }); $(".accept").droppable({ accept: ".draggable", drop: function (event, ui) { $(this).append(ui.helper); $(this).droppable('disable'); ui.draggable.position({ of: $(this), my: 'left+1 top+1', at: 'left top' }); } }); });</code>
$(document).ready(function () {
        $(".draggable").draggable({
        start: function(event, ui){
        // Line below causes a script error
        //    $(this).parent().droppable('enable');
        },
            revert: "invalid",
            helper: "original",
            zIndex: 100
        });  

        $(".accept").droppable({
            accept: ".draggable",
            drop: function (event, ui) {
                $(this).append(ui.helper);
                $(this).droppable('disable');
                ui.draggable.position({
                of: $(this),
                my: 'left+1 top+1',
                at: 'left top'
            });
            }
        });
    });
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>body {
height: 100vh;
margin: 0;
}
.box {
width: 100px;
height: 100px;
border: 1px solid #ccc;
margin-right: 10px;
overflow: hidden;
float: left;
background-color: #0f0;
}
.ui-droppable-disabled {
background-color: #f00;
}
.draggable {
width: 98px;
height: 88px;
cursor: move;
border: 1px solid #999;
margin-bottom: 10px;
background-color: #f0f0f0;
float: left;
}</code>
<code>body { height: 100vh; margin: 0; } .box { width: 100px; height: 100px; border: 1px solid #ccc; margin-right: 10px; overflow: hidden; float: left; background-color: #0f0; } .ui-droppable-disabled { background-color: #f00; } .draggable { width: 98px; height: 88px; cursor: move; border: 1px solid #999; margin-bottom: 10px; background-color: #f0f0f0; float: left; }</code>
body {
    height: 100vh;
    margin: 0;
}
.box {
    width: 100px;
    height: 100px;
    border: 1px solid #ccc;
    margin-right: 10px;
    overflow: hidden;
    float: left;
    background-color: #0f0;
}
.ui-droppable-disabled {
    background-color: #f00;
}
.draggable {
    width: 98px;
    height: 88px;
    cursor: move;
    border: 1px solid #999;
    margin-bottom: 10px;
    background-color: #f0f0f0;
    float: left;
}
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js" integrity="sha256-xLD7nhI62fcsEZK2/v8LsBcb4lG7dgULkuXoXB/j91c=" crossorigin="anonymous"></script>
<script src="../js/jquery.ui.touch-punch.min.js"></script>
</head>
<body>
<div class="box ui-droppable-disabled" id="box1">
<div class="draggable ui-widget-content" id="dragObject1">
<p>Drag me 1!</p>
</div>
</div>
<div class="box ui-droppable-disabled" id="box2">
<div class="draggable ui-widget-content" id="dragObject2">
<p>Drag me 2!</p>
</div>
</div>
<div class="box accept" id="box3"> </div>
<div class="box accept" id="box4"></div>
<div class="box accept" id="box5"></div>
<div class="box ui-droppable-disabled" id="box6">
<div class="draggable ui-widget-content" id="dragObject3">
<p>Drag me 3!</p>
</div>
</div></code>
<code><!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script> <script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js" integrity="sha256-xLD7nhI62fcsEZK2/v8LsBcb4lG7dgULkuXoXB/j91c=" crossorigin="anonymous"></script> <script src="../js/jquery.ui.touch-punch.min.js"></script> </head> <body> <div class="box ui-droppable-disabled" id="box1"> <div class="draggable ui-widget-content" id="dragObject1"> <p>Drag me 1!</p> </div> </div> <div class="box ui-droppable-disabled" id="box2"> <div class="draggable ui-widget-content" id="dragObject2"> <p>Drag me 2!</p> </div> </div> <div class="box accept" id="box3"> </div> <div class="box accept" id="box4"></div> <div class="box accept" id="box5"></div> <div class="box ui-droppable-disabled" id="box6"> <div class="draggable ui-widget-content" id="dragObject3"> <p>Drag me 3!</p> </div> </div></code>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script> 
<script   src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"   integrity="sha256-xLD7nhI62fcsEZK2/v8LsBcb4lG7dgULkuXoXB/j91c="   crossorigin="anonymous"></script> 
<script src="../js/jquery.ui.touch-punch.min.js"></script>
</head>
<body>
<div class="box ui-droppable-disabled" id="box1">
    <div class="draggable ui-widget-content" id="dragObject1">
        <p>Drag me 1!</p>
    </div>
</div>
<div class="box ui-droppable-disabled" id="box2">
    <div class="draggable ui-widget-content" id="dragObject2">
        <p>Drag me 2!</p>
    </div>
</div>
<div class="box accept" id="box3"> </div>
<div class="box accept" id="box4"></div>
<div class="box accept" id="box5"></div>
<div class="box ui-droppable-disabled" id="box6">
    <div class="draggable ui-widget-content" id="dragObject3">
        <p>Drag me 3!</p>
    </div>
</div>

How can I re-enable droppable on the parent div when moving the draggable from it?

Also, on a side note, how can I get the draggable to appear over the droppable rather than inside them?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật