JavaScript How to bind jquery droppable to a dynamically created element

I'm having a serious trouble with attaching droppable functionality to dynamically created elements.! I cannot bind droppable when the item is created since there is an ajax call going when the a certain element is dropped! how can I bind the droppable functionality to dynamic elements!

Please respond!

The droppable function :

$('.bill-item-list').droppable({
                    accept: '.item',
                    drop: function( event, ui ) {
                        var clone = bill.clone();
                        var droppable = $(this);
                        var jsonObject = 'itemId=' + ui.draggable.attr('id') + '&billId=' + $(this).parent().attr('id');
                        $.ajax({
                            url: "/addItemToBill",
                            type: "POST",
                            data: jsonObject,
                            dataType: "json",
                            beforeSend: function(x) {
                                if(x && x.overrideMimeType) {
                                    x.overrideMimeType("application/json;charset=UTF-8");
                                }
                            },
                            success: function(result){
                                if(result.status = true){
                                    clone.find('.bill-item-name-left').html(ui.draggable.find('.item-name').children('h4').html());
                                    clone.find('.bill-item-name-right').html(ui.draggable.find('.item-price').children('h4').html());
                                    clone.find('.bill-item-price').html(ui.draggable.find('.item-price').children('h4').html() + ".00 USD" );
                                    clone.find('.bill-item-amount').html("1");
                                    if(droppable.height() > 300){
                                        droppable.css('overflow-y','scroll');
                                        droppable.css('height', '320px')
                                    }
                                    clone.draggable({
                                        revert : true,
                                        zIndex: 1,
                                        containment: "window",
                                        opacity: 0.5,
                                        cursor: "move",
                                        helper: function() { return $(this).clone().appendTo('body').show(); }
                                    });
                                    clone.insertBefore(droppable.find('.item-drop-point')).hide().fadeIn("slow");
                                }

                            }
                        });
                    }
                });

And the dynamic element creation

function getBillInformation(Status,billingDate,User){
    var parent = "";
    var status = "";

    switch(Status){
        case "OPEN":
            parent = $('#tab-1');
            status = "O";
            break;
        case "SETTLED":
            parent = $('#tab-2');
            status = "S";
            break;
        case "CANCEL":
            parent = $('#tab-3');
            status = "C";
            break;
    }

    var billList = parent.find('#bill-list').first();
    var bill = parent.find('.bill').first();
    var billItemList = parent.find('.bill-item-list').first();
    var billItem = parent.find('.bill-item').first();
    var billPanel = parent.find('#bill-panel').first();

    var jsonObject = "billStatus=" + status + "&billingDate=" + billingDate + "&user=" + User;

    ajaxCall("/getBillingInformation","POST",jsonObject,function(response){
        billPanel.empty();

        billItemList.find('.bill-item').each(function(){
            $(this).remove();
        })

        for(var i = 0; i < response.bills.length; i++){
            var clone = bill.clone();
            clone.attr('id', response.bills[i].billId);
            clone.find('.bill-number').html(response.bills[i].billNo);
            clone.find('.amount').html(response.bills[i].billTotal + " USD");

            clone.find('.room-number').html(response.bills[i].roomNo);
            clone.find('.table-name').html(response.bills[i].tableNo);


            if(response.bills[i].itemsList.length != 0){
                for(var j = 0; j < response.bills[i].itemsList.length; j++){
                    var billItemClone = billItem.clone();
                    billItemClone.find('.bill-item-name-right').html(response.bills[i].itemsList[j].amount);
                    billItemClone.find('.bill-item-amount').html(response.bills[i].itemsList[j].qty);
                    var total = (response.bills[i].itemsList[j].amount) * (response.bills[i].itemsList[j].qty);
                    billItemClone.find('.bill-item-price').html(total + ".00 USD");
                    billItemClone.draggable({
                        revert : true,
                        zIndex: 1,
                        containment: "window",
                        opacity: 0.5,
                        cursor: "move",
                        helper: function() { return $(this).clone().appendTo('body').show(); }
                    });
                    clone.find('.bill-item-list').prepend(billItemClone);
                }
            }

            billPanel.prepend(clone);
        }
    });

}
Answer:1

I have an object whose value may be undefined sometimes. So is it possible / valid / good practice to test it with an if case like below : if(params === undefined) { alert("sound." + params);...

I have an object whose value may be undefined sometimes. So is it possible / valid / good practice to test it with an if case like below : if(params === undefined) { alert("sound." + params);...

I'm working with angular material design. (https://material.angularjs.org/#/) I have the following piece of code: <md-input-container padding> <label>Some date</label> <input ...

I'm working with angular material design. (https://material.angularjs.org/#/) I have the following piece of code: <md-input-container padding> <label>Some date</label> <input ...

  1. angular material design icons
  2. angular material design components
  3. angular material design examples
  4. angular material design table
  5. angular material design template
  6. angular material design dialog
  7. angular material design buttons
  8. angular material design checkbox
  9. angular material design layout
  10. angular material design tutorial
  11. angular material design vs bootstrap
  12. angular material design slider
  13. angular material design form
  14. angular material design github
  15. angular material design dropdown
  16. angular material design theme
  17. angular material design modal
  18. angular material design bootstrap
  19. angular material design library
  20. angular material design drag and drop

Though you can use a variable without declaring it in javascript, the misuse of variable will cause hard-to-solve errors. For example, the following code will cause endless loop. for(i=0;i<100;i+...

Though you can use a variable without declaring it in javascript, the misuse of variable will cause hard-to-solve errors. For example, the following code will cause endless loop. for(i=0;i<100;i+...

  1. force variable declaration vba
  2. force variable declaration
  3. powershell force variable declaration
  4. python force variable declaration
  5. php force variable declaration
  6. javascript force variable declaration
  7. autoit force variable declaration
  8. matlab force variable declaration
  9. bash force variable declaration
  10. vbscript force variable declaration
  11. perl force variable declaration
  12. excel vba force variable declaration

I have a page which has a form in it named as profile updation and when a user comes to this page for any updation of his profile that time he only update 1 or 2 fields so every time form checks the ...

I have a page which has a form in it named as profile updation and when a user comes to this page for any updation of his profile that time he only update 1 or 2 fields so every time form checks the ...

  1. angular form validation example
  2. angular form validation on submit
  3. angular form validation email
  4. angular form validation not working
  5. angular form validation phone number
  6. angular form validation on blur
  7. angular form validation number
  8. angular form validation messages
  9. angular form validation on change
  10. angular form validation max length
  11. angular form validation regex
  12. angular form validation template driven
  13. angular form validation numbers only
  14. angular form validation min value
  15. angular form validation reset
  16. angular form validation unit test
  17. angular form validation disable button
  18. angular form validation date
  19. angular form validation async
  20. angular form validation checkbox