jQuery UI Draggable option() Method
Last Updated :
20 Jan, 2022
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 any parameter’s value of the Draggable widget. We can also get all the options as key-value pairs using this method.
Syntax:
1. If the user wants any option’s value, the option name should be passed in the option(optionName) method. The optionName should be a string type.
var isEnhanced = $("Selector").draggable("option", "enhanced");
Parameter:
- optionName: This parameter is the input that we need to pass in the form of a string for which we need to get the value.
- Return type: We get the respective return value based on the option data type.
2. To get all the options as the key-value pairs, you just need to call the option() method with no parameter is passed to the method.
var options= $("Selector").draggable("option");
Return type: This method returns the list of key-value pairs of all the options as optionName-optionValue pairs set.
3. To set the value of any option, you just need to call the option(optionName, value) with the optionName and the value as the parameters.
$("Selector").draggable("option", "enhanced", "false");
Parameters:
- optionName: The option method required the option name as the first parameter and this parameter is of string type.
- value: The option method required the option’s name as the second parameter and this parameter is of string type.
4. We can also set multiple options instead of only one, you just need to call the option(options) method where options are the list of options.
$("Selector").draggable("option", {enhanced: false, disabled: true});
Parameter:
- option: It is the map of the optionName-value pairs as input to set the options corresponding to the values passed, which is of the object type.
CDN Link: Add the following jQuery Mobile scripts that you will be needed for your project.
<link rel=”stylesheet” href=”https://code.jquery.com/ui/1.12.1/themes/smoothness/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 Mobile Draggable option() method.
HTML
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "utf-8" >
< link href =
rel = "stylesheet" >
< script src =
</ script >
< script src =
</ script >
< style >
.drag
{
width:90px;
height:50px;
border:1px solid black;
background-color:blue;
}
.drop2
{
width:200px;
height:50px;
border:1px solid black;
float:center;
background-color:green;
}
</ style >
< script >
$(function () {
$(".drag").draggable();
$(".drop2").droppable({
drop: function (event, ui) {
$(this).find("p").html("Dropped!");
}
});
});
$(function () {
$("#btn").on('click', function () {
var options = $(".drag").draggable("option");
document.getElementById('spanID').innerHTML +=
"No of key/value pair present : " +
Object.keys(options).length;
});
});
</ script >
</ head >
< body >
< center >
< h1 style = "color:green;" >GeeksforGeeks</ h1 >
< h3 >jQuery UI Draggable option() method</ h3 >
< div class = "drag" >
< p >Drag</ p >
</ div >
< br >
< div class = "drop2" >
< p >Drop here</ p >
</ div >
< br >
< input type = "button" id = "btn"
style = "width:200px;height:40px;"
value = "Option" >
< h4 >< span id = "spanID" ></ span ></ h4 >
</ center >
</ body >
</ html >
|
Output:

jQuery Mobile Draggable option() method
Reference: https://api.jqueryui.com/draggable/#method-option
Similar Reads
jQuery UI Droppable 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 Droppable option() method. Using this method, we can get, set or update a
3 min read
jQuery UI dialog option() Method
This action gets an object containing key/value pairs representing the current dialog options hash. This method does not accept any argument Syntax: var a = $( ".selector" ).dialog("option"); Approach: First, add jQuery UI scripts needed for your project. <link href = "https://code.jquery.com/ui/
1 min read
jQuery UI Draggable opacity 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 opacity Option is used to set the opacity for the helper while being dragged. Syntax: $( ".selector" ).dr
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 option Method
jQuery UI option method is used to check if a method returns a boolean value representing if an object option exist or not. Syntax: $( ".selector" ).button( "option") Parameters: This method does not accept any parameters. Return values: This method returns a object value. Links for jQuery UI librar
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
jQuery UI Draggable axis 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 axis Option is used to dragging the element either on the horizontal (x) or vertical (y) axis. The possib
1 min read
jQuery UI Draggable scope 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 add
2 min read
jQuery UI Draggable stack 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 add
2 min read