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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:19:03+00:00 2026-05-16T07:19:03+00:00

I want a user to be able to reorder a list on a click

  • 0

I want a user to be able to reorder a list on a click event. Here is my code:

$(function() {

  $('#reOrder li').each(function, (index) {

    $(this).attr('id', index);

  });

  $("#reOrder").delegate("li", "click", function() {

    var $indexItem = $(this).index('#reOrder li');

    var $thisTxt = $(this).text();

    var $prevTxt = $(this).prev('li').text();

    $($thisTxt).replaceWith($prevTxt);

    //alert($thisTxt);

    //alert($prevTxt);

  });

});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul id="reOrder">
  <li>Item 1</li>
  <li>Item 2</li>
  <li>Item 3</li>
  <li>Item 4</li>
</ul>

So in this example I would like to move the clicked li item and its contents to the position above in the DOM. I suppose strictly speaking it is being moved down in the index of li items.

This is going to be extended later to include buttons that move li items up and down and a submit button that saves the order/state of the list items.

I have found a lot of info on drag and drop (which is not required) but not much on this sort of functionality.

  • 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-16T07:19:04+00:00Added an answer on May 16, 2026 at 7:19 am

    Something you might want to check out is the jQuery UI sortable

    If you simply want to move items around by clicking etc. have a look at the following methods:

    detach function

    DOM insertion functions

    $("document").ready(function() {
        $("#reOrder li").click(function() {
            var index = $("#reOrder li").index(this);
            if (index != 0) {
               // li item is not sitting in the first position
               $("#reOrder li:eq(" + (index - 1) + ")").before(this);
            }
        });
    });
    

    Detach will allow you to remove the clicked element from the DOM and will have a copy available, you can then reinsert in the desired position using one of the DOM insertion functions.

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

Sidebar

Related Questions

I want the user to be able to see the source code of the
I want user to be able to paste their html/css code? eg. from internet.
I want user to be able to input like this: 5+6*t+sin(2*t) , so it
I want the user to be able to click on the div, to slideDown
I want the user to be able to make some preferences like colors, prefered
I want the user to be able to see my application in the menu
I want the user to be able to enter a name for a file
I want the user to be able to select an option, which would change
I want my user to be able to hit the submit button and have
I want the user to be able to choose from a dropdown Combobox listing

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.