Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make New Div Draggable in Jquery

I am trying to make jquery add new div and then make it draggable but i have been trying and looking on google and i can't find anything here is my code below

 $(document).ready(function() {

 $("#draggable").draggable({ 
   containment: 'parent',
   handle: 'drag_border',
   drag: function(e, ui) {
          var top = ui.position.top;
          var left = ui.position.left;
          $("#top").html(top);
          $("#left").html(left);
           }
       }); 
   });

       function New_Text() {   
            $("<div id=\"draggable\" style=\"width: 200px; height: 50px; border:dashed thin; background-color: #fff\">Drag me</div>").appendTo("div#drag_border"); 
              }

Thank you

like image 637
Rickstar Avatar asked Aug 21 '10 17:08

Rickstar


People also ask

How do you make a div draggable?

To make an object draggable set draggable=true on that element. Just about anything can be drag-enabled: images, files, links, files, or any markup on your page.

Can Div be draggable?

Draggable Div is a kind of element that you can drag anywhere.

What is jQuery draggable?

jQueryUI provides draggable() method to make any DOM element draggable. Once the element is draggable, you can move that element by clicking on it with the mouse and dragging it anywhere within the viewport.


1 Answers

If you are using jQuery UI, then create your element and make it draggable:

$("<div />").draggable();
like image 64
cllpse Avatar answered Oct 06 '22 11:10

cllpse