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
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.
Draggable Div is a kind of element that you can drag anywhere.
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.
If you are using jQuery UI, then create your element and make it draggable:
$("<div />").draggable();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With