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

  • Home
  • SEARCH
  • 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 6846199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:35:33+00:00 2026-05-27T00:35:33+00:00

I have several dynamically generated unordered lists. The <li> ‘s within them are draggable/droppable

  • 0

I have several dynamically generated unordered lists. The <li>‘s within them are draggable/droppable elements which are apended into a div when dropped there.

I want to be able to return these <li>‘s into their original lists and at the same index so that they are in exactly the same position as before.

I have been able to achieve this by doing the following:-

When dragging the element using the .data function as below:

$item.data('originalParent', $(this).prev());

Then when I return the element using this:-

.insertAfter( $item.data('originalParent') )

This of course works great, however a problem arises when I have also dragged the previous <li> into the droppable box since the item is appended next to that, instead of in the original parent at the correct index.

How else can I dynamically store the index location so that I can return it to the correct parent <ul> at the correct <li> index? Even if the number of <li> elements has changed in the <ul>.

I hope this is clear enough as I am finding it difficult to articulate.

Thanks

  • 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-27T00:35:33+00:00Added an answer on May 27, 2026 at 12:35 am

    gordyr to expand on my comments since its easier to type and show examples here if you have a setup like

    <ul list="1">
        <li list="1" item="1"></li>
        <li list="1" item="2"></li>
    </ul>
    <ul list="2">
        <li list="2" item="1"></li>
        <li list="2" item="2"></li>
    </ul> 
    

    When a list item is dropped you can grab and store its list and item attributes using

    list =  $(this).attr('list');
    item =  $(this).attr('item');
    // store this list and item variable data with the div or parent of where ever the list item was dropped
    

    when you want to reset the dragged list item back to its original spot in the UL it came from, read the list and item variable you stored with it, we’ll say you grabbed them and they are stored in list and item and the li to restore is element

    To restore the list item to its original position you can do something like:

    if (item == 1)
    {
        // the list item being restored is the first so prepend it to the beginning of the list it came from
        element.prependTo( $('ul[list=' + list + ']') );
    }
    else
    {
        // the list item is not the first so find the item before it in the list it came from and insert it after that list item
        element.insertAfter( $('ul[list=' + list + '] li[item=' + (item - 1) + ']') );
    }
    

    Hope this helps any, I could be just way off on what your trying to do. The examples above still would need to be expanded upon, like the last one, since it’s just going back one item in the list, that item could of been moved also so it wont be in the list so you’d have to keep iterating back till you found the next item in the list and insert it after that one.

    If the item is 4, look for item 3 in the list, if not there then 2, if not there then 1, if 1 isn’t there then prepend to the beginning of the list.

    • 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 several dynamically generated DropDownLists. The DDs load and display
I have several a tags as shown below on a dynamically generated page <a
I have a selection list that is generated dynamically, it lists a number of
I have a form that is generated based on several DataTemplate elements. One of
I have several elements in my web page generated by JavaScript. Here's an example
I have several DropDownLists on a form which are dynamically populated as they move
I have a datagrid which has several static and more dynamicaly generated coloumns. The
I have a page that needs to load several dynamically generated images. Everything works
I have several textboxes that are generated dynamically based on some results I get
I have several buttons on my app that are being created dynamically. They are

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.