Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

jQuery UI Sortable grid Option

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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 Sortable grid Option. Using this option, we can snap the sorting element or helper to a grid, every x, and y pixels. The default value of this option is false.


The grid option takes an array value and the syntax is as follows.

$( ".selector" ).sortable({
    grid: [ 20, 10 ]

Get the grid option

var grid = $( ".selector" ).sortable( "option", "grid" );

Set the grid option

$( ".selector" ).sortable( "option", "grid", [ 20, 10 ] );

CDN Link: The following jQuery Mobile scripts will be needed for your project so we need to add these scripts to your project.

<link rel=”stylesheet” href=””>
<script src= “”></script>
<script src= “”></script>

Example: This example describes the uses of the jQuery UI Sortable grid Option.


<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <link rel="stylesheet"
        #sortable {
            list-style-type: none;
            width: 50%;
        #sortable li {
            margin: 10px 0;
            padding: 0.5em;
            font-size: 25px;
            height: 20px;
            background-color: green;
            margin-left: 50px;
            padding: 0.5;
            font-size: 20px;
            height: 40px;
            width: 40%;
        $(function () {
            $("#btn").on('click', function () {
                var grid = $("#sortable").sortable( "option", "grid" );
                document.getElementById('gfg').innerHTML +=
                "Grid pixels : " + grid;
        $(function () {
            $("#sortable").sortable( "option", "grid", [ 20, 10 ] );
        <h1 style="color: green;">
        <h4>jQuery UI Sortable grid Option</h4>
        <ul id="sortable">
        <input type="button" id="btn"
            value="Get Grid">
        <h4><span id="gfg"></span></h4>


jQuery UI Sortable gird Option

jQuery UI Sortable grid Option


My Personal Notes arrow_drop_up
Last Updated : 09 May, 2022
Like Article
Save Article
Similar Reads
Related Tutorials