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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:00:47+00:00 2026-06-11T20:00:47+00:00

The source: <ul class=supercategory> <li> <div class=supcat> <h4> <a class=new href=/header1.html>header 1</a> </h4> <ul

  • 0

The source:

<ul class="supercategory">
    <li>
    <div class="supcat">
        <h4>
        <a class="new" href="/header1.html">header 1</a>
        </h4>
        <ul class="category">
            <li><a href="item1.html">Item 1</a></li>
            <li><a href="item2.html">Item 2</a></li>
        </ul>
    </div>
    </li>
    <li style="" class="">
    <div class="supcat">
        <h4>
        <a class="new" href="/header2.html">Header 2</a>
        </h4>
        <ul class="category">
            <li><a href="item1.html">Item 1</a></li>
            <li><a href="item2.html">Item 2</a></li>
        </ul>
    </div>
    </li>
</ul>
<div id="test">
</div>

a lit bit of css:

ul.supercategory { background: lightblue; }
.new{ background: yellow; }

and a jQuery UI force:

$('.supercategory').sortable({
            cursor: 'move',
            axis: 'y',
            revert: true,
            stop: function (event, ui) {  }
        });

I know that to get an object of the current dragged element I simply must to make something this:

stop: function(event, ui) { var obj = ui.item; }

But how to get an object of placed element instead of I dragged to new position?

For example, if I dragged first li on the new position (it will 2nd li) the second li was placed on the place instead of my, how to get this element as object in jQuery UI sortable?

Watch my fiddle: http://jsfiddle.net/Stasonix/jCMuQ/1/

upd 1. First of all a fiddle. http://jsfiddle.net/Stasonix/jCMuQ/5/

Than code:

var is_received = false;

$('.supercategory').sortable({
            cursor: 'move',
            axis: 'y',
            revert: true,
            receive: function(event, ui){ is_received = true;  },
            stop: function (event, ui) {

                is_received = true;

            },

    deactivate: function(event, ui) {

        if (is_received){

            $('#test').text(ui.item.find('.new').attr('href'));

            is_received=false;

        }            

    }


 });

Well… still need a solution, it’s not works seems.

  • 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-06-11T20:00:48+00:00Added an answer on June 11, 2026 at 8:00 pm

    You can try this to get the new object you dragged by keeping track of your object’s index / position, and by using the events start and deactivate like this:

    // Define static variables to keep track of the index / position of your dragged object
    var prev_index =  null;   // Previous index / position of your dragged object
    var next_index = null;    // Next index / position of your dragged object
    
    $('.supercategory').sortable({
        cursor: 'move',
        axis: 'y',
        revert: true,
        start : function(event, ui) {
            prev_pos = ui.item.index();
        },
        deactivate : function(event, ui) {
            next_pos = ui.item.index();
        },
        stop : function(event, ui) {
            // Your new object: "el"
            var el = null;
    
            if(next_pos > prev_pos)
                el = $(".mydrag").get(next_pos-1); // Your previous object has been dragged! Your previous object was initially above your new object (Dragging downward)
            else if(next_pos<prev_pos)
                el = $(".mydrag").get(next_pos+1); // Your previous object has been dragged!  Your previous object was initially below your new object (Dragging upward)
            else
                el = $(".mydrag").get(prev_pos);   // Your previous object was not dragged and is at the same position
    
            $('#test').text($(el).find('.new').attr('href'));
        }
    });
    

    The thing is,

    • if your object was dragged successfully, depending on whether you drag your object downward or upward, the new object you’re looking for will be located above or below the dragged object, so: at the new index / position of your dragged object -1 / +1
    • however, if your object was not dragged successfully, there is “no new object”, so your new object is your dragged object.

    Make sure to add the class .mydrag to your draggable li elements:

    <ul class="supercategory">
        <li class="mydrag">
            <div class="supcat">
                <h4>
                    <a class="new" href="/header1.html">header 1</a>
                </h4>
                <ul class="category">
                    <li><a href="item1.html">Item 1</a></li>
                    <li><a href="item2.html">Item 2</a></li>
                </ul>
            </div>
        </li>
        <li class="mydrag">
            <div class="supcat">
                <h4>
                    <a class="new" href="/header2.html">Header 2</a>
                </h4>
                <ul class="category">
                     <li><a href="item1.html">Item 1</a></li>
                     <li><a href="item2.html">Item 2</a></li>
                 </ul>
            </div>
        </li>
    </ul>
    <div id="test">
    </div>
    

    I’m not sure if this solution is what you were exactly looking for…
    You can ask me question if I was not clear.

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

Sidebar

Related Questions

Source class Program { static void Main(string[] args) { var fw = new FileSystemWatcher(@M:\Videos\Unsorted);
Recently, I've released an open-source class - wrapper of API functions available from one
I have this class: public class Source extends Node { protected DistributionSampler delay ;
Here's the relevant bit of the source code: class Dice { String name ;
Superclass source code public class Date { private int month; private int day; private
Consider this source: public partial class FormTest : Form { private Test test {
I want to port an small open source AES encryption class to Android, and
I've seen at least one reliable source (a C++ class I took) recommend that
Have there been incompatibilities between Java releases where Java source code/Java class files targeting
My class with an event: public class WindowModel { public delegate void WindowChangedHandler(object source,

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.