Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1052817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:09:20+00:00 2026-05-16T17:09:20+00:00

This question is all over SO, but no one seems to have had the

  • 0

This question is all over SO, but no one seems to have had the same problem as I have.

When I do something like this

$(function(){
    $('#unique-ul').sortable({items:'li'});
});

I’d expect it to “just work”. By and large, it does. I can drag any <li> from any list to any other list, and any sublist of that <li> is dragged with it.

However, when dragging, it seems to get really confused about where it should be dropped. Here’s an example using 1.8.0; it displays the same behaviour.

http://jsbin.com/ewuxi3/

All the other responses I’ve found about this lead me to believe that this behaviour is supported by jQuery UI; for example, here is a bug registered against 1.7 about nested draggables: http://dev.jqueryui.com/ticket/4333

I can’t find anyone else who has had this issue so it suggests I am Doing It Wrong. Any clues?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:09:21+00:00Added an answer on May 16, 2026 at 5:09 pm

    this happens because Sortable doesn’t really know if you are above the nested <li> or the one that contains it. One solution is to use a structure like this:

    $(document).ready(function() {
      $('#sortable-category').sortable({
        items: 'li',
        toleranceElement: '> div'
      });
    });
    * {
      box-sizing: border-box;
      list-style: none;
    }
    
    ul > li > div {
      margin-bottom: 5px;
      border-bottom: 1px solid #ddd;
    }
    
    ul,
    ul > li > div {
      display: block;
      width: 100%;
      float: left;
    }
    
    ul > li {
      display: block;
      width: 100%;
      margin-bottom: 5px;
      float: left;
      border: 1px solid #ddd;
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
    
    <ul id="sortable-category">
      <li>
        <div>Item 1</div>
        <ul>
          <li>
            <div>Subitem 1</div>
          </li>
          <li>
            <div>Subitem 2</div>
          </li>
        </ul>
      </li>
      <li>
        <div>Item 2</div>
      </li>
      <li>
        <div>Item 3</div>
      </li>
    </ul>

    and set the option toleranceElement: '> div'. I don’t know why it isn’t documented, but it’s in there and it tells Sortable to take into consideration just the <div> when calculating intersections.

    In case you are interested, I recently developed a plugin which makes nested sorting easier, allowing to create new nested lists on the fly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is similar to this one, but with an extra wrinkle: Auto-removing all
This is a big-picture question... but I also have details on the problem I
I know this question seems to be answered all over stackoverflow and the web,
I've searched all over and couldn't find an answer to this seemingly common question,
First of all: This question is not directly programming related. However, the problem only
Dear all,Now i have this question in my java program,I think it should be
Im sure this question is so easy for all you experts, but I am
Sorry for the odd question but this is one that makes me want to
I have an architectural question. I have a project that is conceptually something like
I feel like this is a stupid question because it seems like common sense

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.