Search code examples
jqueryjquery-uijquery-ui-draggablejquery-ui-sortablejquery-resizable

jQuery events to new created div


A visitor could drag and drop different items to multiple containers which have an individual sortable so the items in each container could be changed. At last, every container could be resized. So, this is all working well.

Unfortunately a problem occurred when the visiter create a newly div which is an container. This container should have the same opportunities as the containers which loading while the page loads. But since the container is newly added to the page, the functions aren't working.

I've tried different things like appendTo() and call the functions draggable(), resizable() etc again, but al doesn't working.


Solution

  • It should work if you do something like this, event will be applied to new elements :

    $('span').on('resize', function() { ... }); // or whatever event 'click', 'mousedown'..
    
    var label = $(document.createElement('span'));
    
    td.append(label);