jQuery UI Draggable appendTo Option
Last Updated :
31 Jan, 2022
jQuery UI is a web-based technology and consists of GUI widgets, visual effects, and themes implemented using the jQuery, JavaScript Library. jQuery UI is the best tool for building UI interfaces for the webpages. It can also be used to build highly interactive web applications or can be used to add widgets easily.
In this article, we will learn how to use the jQuery UI Draggable appendTo Option. This option allows us to find which element the draggable helper should be appended to while dragging. The default value of this option is "parent".
This option supports the following multiple types:
- jQuery: This type is a jQuery object containing the element to append the helper to.
- Element: This type is the element to append the helper to.
- Selector: This type is a selector specifying which element to append the helper to.
- String: This type is the string "parent" will cause the helper to be a sibling of the draggable.
Syntax:
The appendTo option takes a above-defined type value and the syntax is as follows.
$( ".selector" ).draggable({ appendTo: "body" });
Get the appendTo option:
var appendTo = $( ".selector" ).draggable( "option", "appendTo" );
Set the appendTo option:
$( ".selector" ).draggable( "option", "appendTo", "body" );
CDN Link: The following jQuery Mobile scripts will be needed for your project so we need to add these scripts to your project.
<link href = “https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css” rel = “stylesheet”>
<script src = “https://code.jquery.com/jquery-1.10.2.js”></script>
<script src = “https://code.jquery.com/ui/1.10.4/jquery-ui.js”></script>
Example: This example describes the uses of the jQuery UI Draggable appendTo Option.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet"
href=
"https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css">
<script src=
"https://code.jquery.com/jquery-1.10.2.js">
</script>
<script src=
"https://code.jquery.com/ui/1.10.4/jquery-ui.js">
</script>
<style>
.dragg {
width: 90px;
height: 40px;
border: 1px solid black;
background-color: blue;
}
.dropp2{
width: 250px;
height: 40px;
border: 1px solid black;
float: center;
background-color: green;
}
#btn
{
padding: 0.5;
font-size: 20px;
width: 20%;
}
</style>
<script>
$(function () {
$("#btn").on('click', function () {
var appendTo = $(".dragg")
.draggable( "option", "appendTo" );
$("#gfg").html("Draggable are appended to: "+appendTo);
});
});
$(function () {
$(".dragg").draggable({
appendTo: "body"
});
$(".dropp2").droppable({
drop: function (event, ui) {
$(this).find("p").html("Dropped!");
}
});
});
</script>
</head>
<body>
<center>
<h1 style="color:green;">GeeksforGeeks</h1>
<h3>jQuery UI Draggable appendTo Option</h3>
<div class="dragg">
<p>Drag</p>
</div>
<br>
<div class="dropp2">
<p>Drop here</p>
</div>
<br>
<input type="button"
id="btn"
value="Click">
<h3><span id="gfg"></span></h3>
</center>
</body>
</html>
Output:
jQuery UI Draggable appendTo OptionReference: https://api.jqueryui.com/draggable/#option-appendTo
Similar Reads
jQuery UI Draggable disabled Option The jQuery UI consists of GUI widgets, visual effects, and themes implemented using jQuery, CSS, and HTML. jQuery UI is great for building UI interfaces for the webpages. The jQuery UI Draggable disabled Option is used to disable the draggable element if it set to true. Syntax: $( ".selector" ).drag
1 min read
jQuery UI Draggable containment Option jQuery UI consists of GUI widgets, visual effects, and themes implemented using the jQuery JavaScript Library. jQuery UI is great for building UI interfaces for the webpages. It can be used to build highly interactive web applications or can be used to add widgets easily. In this article, we are goi
2 min read
jQuery UI Dialog draggable Option Dialog draggable option if set to true the dialog box will be draggable or if set to false the dialog box will not be draggable. By default, value is true. Syntax: $( ".selector" ).dialog({ draggable: true }); Approach: First, add jQuery UI scripts needed for your project. <link href = "https://c
1 min read
jQuery UI Draggable cancel Option jQuery UIÂ is a web-based technology and consists of GUI widgets, visual effects, and themes implemented using the jQuery, JavaScript Library. jQuery UI is the best tool for building UI interfaces for the webpages. It can also be used to build highly interactive web applications or can be used to ad
2 min read
jQuery UI Draggable snap Option jQuery UI Draggable consists of options, methods, and events. The snap is one of the option of Draggable. When the snap option is true for any element, it will stick to the other elements that are draggable. We can also use the snap option to another certain element that means we can choose which el
3 min read
jQuery UI Draggable grid Option The jQuery UI consists of GUI widgets, visual effects, and themes implemented using jQuery, CSS, and HTML. jQuery UI is great for building UI interfaces for the webpages. The jQuery UI Draggable grid Option is used to set the dragging helper to a grid, every x, and y pixels. The grid value stored in
1 min read