Having trouble with disabling selection in a jQuery Sortable/Draggable list?

I have implemented HTML5 Sortable for creating a draggable and sortable list on my website.

Challenge

I tried using jQuery's disableSelection() function to prevent the list items from being moved from right to left, but it is not working as expected. Can someone suggest an alternative solution to achieve this?

HTML Code Snippet

<section>
        <h1>Sortable Lists</h1>
        <ul id="sortable1" class="connected sortable list">
            <li draggable="true">Item 1
            </li><li draggable="true">Item 3
            </li><li draggable="true" class="" style="display: list-item;">Item 2
            </li><li draggable="true">Item 4
            </li><li draggable="true">Item 5
            </li><li draggable="true">Item 6
        </li></ul>
        <ul id="sortable2" class="connected sortable list">
            <li class="highlight" draggable="true">Item 1
            </li><li class="highlight" draggable="true" style="display: list-item;">Item 2
            </li><li class="highlight" draggable="true">Item 3
            </li><li class="highlight" draggable="true">Item 4
            </li><li class="highlight" draggable="true">Item 5
            </li><li class="highlight" draggable="true">Item 6
        </li></ul>
    </section>

jQuery Function

$(function () {
       $(".connected").sortable({
           connectWith: ".connected"
        }).disableSelection();
});

Link to Demo

You can view the code in action on this Fiddle

Answer №1

Try using the #id instead of .ClassName and don't forget to include an additional disableSelection() method for a specific #id

 $(function () {

   $("#sortable1").sortable({
       connectWith: "#sortable2"
    }).disableSelection();

    $("#sortable2").sortable({
    }).disableSelection();

});

Check out the updated Fiddle Here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Activating tabs in Drupal 7 by utilizing the URL path

Drupal 7 uses the field group module, which includes a file called horizontal_tab.js. Upon examining this file, I came across the following code snippet: // If the current URL has a fragment and one of the tabs contains an // element that matches the URL ...

Designing a component with Bootstrap-inspired flair

We are currently in the process of transitioning our ASPX CMS website to a new platform, and some of the retired pages will be hosted on a separate website under a subdomain. The new website will be utilizing Bootstrap 4.6, whereas our existing CMS site re ...

Dynamic VueJS HTML element selection depending on a condition

While working with Vue JS, I have the capability to do <h1 v-if="someCondition">MY TITLE</h1> Is it possible to determine the element type based on a certain condition? For instance, depending on someCondition, I would like my title to be ei ...

Is there a way to dynamically adjust the carousel slide indicators based on the changing viewport size?

My carousel is inspired by the one at the following link: I am looking to make a modification where, as the screen size decreases, the bottom links disappear and are replaced with dot indicators for switching between slides. ...

What is the process for generating vertical text with html and css?

I am attempting to create a block on my website that resembles the image below: https://i.sstatic.net/lua4J.png Unfortunately, I have tried but it is not working. Here is the HTML code I used: <div class="timelines"> <div class="timeline_di ...

Utilizing ReactJS to fetch data from Material-UI's <TableRow/> component upon selection - a comprehensive guide

I've integrated Material-UI's <Table/> (http://www.material-ui.com/#/components/table) component with <TableRow/> containing checkboxes in a ReactJS project. While I can successfully select rows by checking the boxes, I am struggling ...

What is the best way to iterate over my JSON data using JavaScript in order to dynamically generate cards on my HTML page?

var data = [ { "name":"john", "description":"im 22", "email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4c7d7e7f0c2b212d2520622f">[email protected]</a>" }, { "name":"jessie", ...

Alter color upon click using jQuery

I am facing an issue with my code where I want to make it so that when a user clicks on one of the glyphs on the side of the page, elements with ids starting with the same letter will remain black while everything else, including other glyphs, turn grey. ...

Why using document ready is ineffective for handling kendo controls

Feel free to test out the code snippet below: <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="http://cdn.kendostatic.com/2014.2.1008/js/kendo.all.min.js"></script> <script type="text/javascript"& ...

The icons at the bottom of the page are not properly aligned

I am having trouble aligning my footer icons, specifically the first 2 images. While the bootstrap icons are centered correctly, the first 2 images are not aligning as expected. I have tried various methods like align-items-center, justify-content-center, ...

What is the best way to store and retrieve all the variable data from a .js file on a user's device?

I'm looking for a way to save and load multiple variables in JavaScript that determine a "save" state. These variables are stored in a file named "variables.js." Is there a simple method to easily save all the information in this file and then load i ...

What is the correct way to prevent a UIWebView from crashing due to a nil value when loading an HTML file in Swift?

My goal is to load a simple all-text html file into a UIWebView using Swift. The test html file that I have created is as follows: <!DOCTYPE: html> <html> <body> test </body> It seems straightforward to me. I have placed the htm ...

Firefox fails to apply styles to elements that are empty

Below is a snippet of code for a table with editable content: table { border-collapse: collapse; } th, td { border: 1px solid gray; padding: 3px 6px; } [contenteditable]:empty:not(:focus)::before { content: attr(data-placeholder); color: gr ...

The website code lacks a dynamically generated <div> element

When using jQuery to dynamically add content to a "div" element, the content is visible in the DOM but not in the view page source. For example: <div id="pdf"></div> $("#btn").click(function(){ $("#pdf").html("ffff"); }); How can I ensur ...

Div with hidden scroll that is compatible with all web browsers

I need to create a hidden scrollable div in my angular application. For those unfamiliar with how it looks, check out the following link: http://jsfiddle.net/5GCsJ/4713/ My application has a fixed-header and fixed-navigation. I want all other content to ...

What steps can I take to implement a functional 'echo' command within a Jquery terminal?

Trying to create an echo command that displays what the user types in a JQuery terminal. Here is the code snippet: <link href="https://unpkg.com/jquery.terminal/css/jquery.terminal.min.css" rel="stylesheet" /> <script src="https://cdnjs.clou ...

Is it recommended to add the identical library to multiple iFrames?

Here's a quick question I have. So, my JSP page has 4 different iFrames and I've included JQuery UI libraries in it: <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" /> <script src="http://c ...

Prevent line breaks when using symbols like ":-)" in CSS/HTML5

I need to display strings containing smileys made of ascii characters such as :-) on a web page without them being split between two lines, especially when they are at the end of a line. Does anyone have a solution for ensuring that the smiley is always d ...

Can you customize the "rem" values for individual Web Components when using Angular 2's ViewEncapsulation.Native feature?

I'm interested in creating a component with ViewEncapsulation.Native that utilizes Bootstrap 4 while others are using Bootstrap 3. Below is the component code with Bootstrap 4: import { Component, ViewEncapsulation } from '@angular/core'; i ...

Entering text into the input field with the string "Foo"<[email protected]> is not functioning correctly

The text in my input is initially filled with this string "foo foo"<<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4f2920200f29202061263b">[email protected]</a>>. However, after an insert, the string now l ...