Open In App

jQuery UI Selectable tolerance Option

Last Updated : 16 Jan, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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.

The jQuery UI Selectable tolerance option is used to determine which mode to use for testing whether the lasso should select an item. The lasso can refer to the element that is to be selected by dragging the box. It is of string type & its default value is “touch”.

The following are the possible values:

  • fit: It specifies when the lasso overlaps the item entirely.
  • touch: It specifies when the lasso overlaps the item by any specific amount.

Syntax:

Initialize selectable element with tolerance option:

$( "Selector" ).selectable({ tolerance: "fit" });
  • Get the default option:
    var tolerance = $( "Selector" ).selectable( "option", "tolerance" );
  • Set the default option:
    $( "Selector" ).selectable( "option", "tolerance", "fit" );

CDN Links: Below are some jQuery Mobile scripts that will be needed for your project so add these to 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 describes the uses of the jQuery Mobile Selectable tolerance Option.

HTML




<!doctype html>
<html lang="en">
  
<head>
    <link rel="stylesheet" href=
    <script src=
    </script>
    <script src=
    </script>
    <style>
        h1 {
            color: green;
        }
          
        #list .ui-selecting {
            background: greenyellow;
        }
          
        #list .ui-selected {
            color: white;
            background: green;
        }
    </style>
    <script>
        $(document).ready(function() {
            $("#Button").on('click', function() {
                var tolerance = $("#list").selectable(
                   "option", "tolerance");
                $("#gfg").html(tolerance);
            });
        });
    </script>
</head>
  
<body>
    <center>
        <h1>GeeksforGeeks</h1>
        <h3>jQuery UI Selectable tolerance Option</h3>
        <ul id="list" style="list-style: none">
            <li>Data Structure</li>
            <li>Algorithm</li>
            <li>C++</li>
            <li>Java</li>
            <li>HTML</li>
            <li>Bootstrap</li>
            <li>PHP</li>
        </ul>
        <input type="button" 
               id="Button" 
               value="Value of the tolerance option">
        <h4>
            <span id="gfg"></span>
        </h4
    </center>
    <script>
        $(document).ready(function() {
            $("#list").selectable();
        });
    </script>
</body>
  
</html>


Output:

jQuery UI Selectable tolerance Option

Reference: https://api.jqueryui.com/selectable/#option-tolerance



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads