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 6817415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:03:07+00:00 2026-05-26T21:03:07+00:00

I have two sortable lists linked together. I have an event listener on the

  • 0

I have two sortable lists linked together.

I have an event listener on the first list calling function “A” on “sortupdate” to do some functionality when I am sorting items within the list or when receiving items from the other list.

I also have an event listener on the second list calling function “B” on “sortreceive” to do some functionality when it has received an item from another list.

My problem is that whenever I move something from list 1 to list 2, function “A” is called as well, causing errors in my code. I would like to add an ‘if’ clause to the beginning of function “A” saying to run this code only if the first list is the target, but I can’t for the life of me figure out how to reference the target.

Or maybe there is a better way to check if an item was dragged out of this list?

/* adding current code */

$("#divMainMenu").bind("sortupdate", function(event, ui) 
    { dropRootCategory(event,ui);})//when the main menu receives a menu item
$("ul.divSubMenu ").bind("sortreceive", function(event, ui) 
    { dropSubMenu(event, ui);})//when the main submenu receives a menu item
function dropRootCategory(event, ui) 
{/*item dropped on root category*/
//do some different stuff
}
function dropSubCategory(event, ui) 
{//item dropped on a sub submenu
//do some stuff
}

I have tried checking the target:

if (event.target.id == 'divMainMenu') { //

which doesn’t work because the target id stays ‘divMainMenu’ no matter where I am dropping to.

Next I tried checking for sender:

if (ui.sender == 'null'){// 

However, this only populated with any information after it passed through the sortupdate phase and went to the sortreceive, so again it triggered the code to run.

/*******Updated with answer
Per Keith’s idea below, I answered this with the following code:
On initiation of the menu, I added a variable holding the length of the original length of the main menu

var numMenuItems = $('#divMainMenu').children().length;

Then for my if statement:

if ($('#divMainMenu').children().length >= numMenuItems){
//do some stuff
}

Thanks again Keith! I was going nuts on this one 🙂

  • 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-26T21:03:07+00:00Added an answer on May 26, 2026 at 9:03 pm

    Ok, I really did find another answer to this.
    By adding a flag to the start event when defining the sortable, AS WELL AS a function call to the stop event :

    $('ul.divSortable').sortable({
        items: "li:not(.liEdit)", //cancel: ".liEdit",
        connectWith: '.divSortable',
        start: function(event, ui) { setOriginalSub(ui); },        
        stop: function(event, ui) { isBeingSorted = false; sortSorter(event, ui); }
    });
    

    and a function which grabs the id before sorting takes place:

    function setOriginalSub(ui) 
    {
        originalSub = $(ui.item[0]).parent().attr('id');
    }
    

    I can now compare the original ID with the current ID.

    function sortSorter(event, ui){
        var parentID = $(ui.item[0]).parent().attr('id');
    }
    

    Brilliant, and I wouldn’t have thought of it without Keith’s help!

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

Sidebar

Related Questions

I have a page with two lists. The list on the left has some
So I have two sortable lists in a web app I'm writing. What I
I'm working with a demo of two sortable jquery lists... but have a problem
At the moment I have two (maybe more) unordered lists which are sortable with
I have two sortable lists, one being nested, with a mouse over effect on
I have two sortable lists that are connected. One is simply on the page,
I tried many things but not successful :( I have two sortable lists connected
I have two connected sortable lists. My code works fine for when I drag
I have two lists with 8 list elements within each one. I would like
I have two lists. At start only the first one has visible elements, the

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.