blue-sky
blue-sky

Reputation: 53866

When div is added to dom enable it to be droppable

Is it possible to allow a new div that is added dynamically to a dom to be made droppable ?

I'm trying this :

var myDroppable = '<div id="myDroppableDiv" >New droppable</div>';
$("#myDroppables").append(myDroppable );

But receive this error :

Object has no method 'droppable'

Upvotes: 1

Views: 418

Answers (2)

Blazemonger
Blazemonger

Reputation: 92953

Just invoke the droppable method as soon as its appended:

$(myDroppable).appendTo('#myDroppables').droppable();

Upvotes: 4

David Thomas
David Thomas

Reputation: 253396

Yep; you can do it this way:

​var d = $('<div />').droppable();​​​​​
​d.appendTo('body');​​​​

JS Fiddle demo.

Upvotes: 1

Related Questions