jQuery UI Draggable instance() Method
Last Updated :
25 Jan, 2022
jQuery UI is a web-based technology and consists of various GUI widgets, visual effects, and themes. These features can be 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 be using the jQuery UI Draggable instance() method to retrieve the draggable's instance object. If the element does not have any associated instance, "undefined" is returned. It does not accept any parameter for functioning.
Syntax:
var Instance = $( ".selector" ).draggable( "instance" );
Parameter: This method does not accept any parameter.
Return type: This method returns an object value that contains the draggable's instance object.
CDN Link: Add the following jQuery Mobile scripts that will be needed for your project.
<link rel=”stylesheet” href=”https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css”>
<script src= “https://code.jquery.com/jquery-1.12.4.js”></script>
<script src= “https://code.jquery.com/ui/1.12.1/jquery-ui.js”></script>
Example: This example demonstrates the jQuery UI Draggable instance() method.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href=
"//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.12.4.js">
</script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js">
</script>
<style>
.drag {
width: 90px;
height: 40px;
border: 1px solid black;
background-color: blue;
}
.drop2,
.drop3 {
width: 200px;
height: 40px;
border: 1px solid black;
float: center;
background-color: green;
}
#btn {
padding: 0.5;
font-size: 25px;
height: 40px;
width: 150px;
}
</style>
<script>
$(function () {
$("#btn").on('click', function () {
var insta = $(".drop2").draggable("instance");
console.log(insta);
});
$(".drag").draggable();
$(".drop2").droppable();
});
</script>
</head>
<body>
<center>
<h1 style="color:green;">
GeeksforGeeks
</h1>
<h3>jQuery UI Draggable instance() method</h3>
<div class="drag">
<p>Drag</p>
</div>
<br>
<div class="drop2">
<p>Drop here</p>
</div>
<br>
<input type="button" id="btn" value="Instance">
<h4><span id="spanID"></span></h4>
</center>
</body>
</html>
Output:
jQuery UI Draggable instance() method
Reference: https://api.jqueryui.com/draggable/#method-instance
Similar Reads
jQuery UI Droppable instance() Method 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
2 min read
jQuery UI Draggable enable() Method 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 enable() method is used to enable the draggable option. This method does not accept any parameter. Syntax: $(
1 min read
jQuery UI Draggable widget() Method 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
2 min read
jQuery UI | draggable() and droppable() methods jQuery UI is a mixture of methods and a set of user interface effects, widgets, interactions and themes which can be provided in the web page using jQuery methods. If you want to build up a powerful web application that includes various features such as dragging, dropping, date picker, tooltips, etc
5 min read
jQuery UI Draggable option() Method jQuery Mobile is a web-based technology that can be used to make responsive content for websites that can be accessed on all types of smartphones, tablets, and desktops. In this article, we are going to learn the jQuery Mobile Draggable option() method. Using this method, we can get, set or update a
3 min read