Player
Player

Reputation: 33

Jquery Draggable / Live

I have:

$(document).ready(function () {

      $(".div1, .div2, .div3, .div4, .div5").draggable();


      $("#menu").click(function () {

           $("<div class='div1'></div>").appendTo("#layout");

      });

});

But the draggable function works just to the divs that already exist when the page is loaded. When I add dynamically, I could not drag them.

My Html:

     <div id="layout">
       <div class="div1"></div>
     </div>

Upvotes: 2

Views: 1417

Answers (2)

Shikiryu
Shikiryu

Reputation: 10219

You just need to add the draggable handler to your new div with :

 $("<div class='div1'></div>").appendTo("#layout").draggable();

for example.

Here's a live example.

Upvotes: 4

Nick Craver
Nick Craver

Reputation: 630379

In your case the easiest solution is to call .draggable() on the new elements as you create them, like this:

$("<div class='div1'></div>").appendTo("#layout").draggable();

Upvotes: 2

Related Questions