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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:31:40+00:00 2026-06-09T18:31:40+00:00

The goal is to move an element before its left sibling or after its

  • 0

The goal is to move an element before its left sibling or after its right sibling.

<ul>
    <li>One</li>
    <li>Two</li>
    <li>Three</li>
    <li>One</li>
</ul>

Given only the index of the element, I need to move it to left or right. Say the index is 1 (LI with “Two” as innerText), then I want to move it to left, the output should be:

<ul>
    <li>Two</li>
    <li>One</li>
    <li>Three</li>
    <li>One</li>
</ul>
  • 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-09T18:31:41+00:00Added an answer on June 9, 2026 at 6:31 pm
    /**
     * @param siblings {jQuery} List of sibling elements to act upon
     * @param subjectIndex {int} Index of the item to be moved
     * @param objectIndex {int} Index of the item to move subject after
     */
    var swapElements = function(siblings, subjectIndex, objectIndex) {
        // Get subject jQuery
        var subject = $(siblings.get(subjectIndex));
        // Get object element
        var object = siblings.get(objectIndex);
        // Insert subject after object
        subject.insertAfter(object);
    }
    $(function() {
        swapElements($('li'), 0, 1);
    });
    ​
    

    ​

    Working example: http://jsfiddle.net/faceleg/FJt9X/2/

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

Sidebar

Related Questions

I have two tables and my goal is to move specific data from the
My Goal: Is to move data from one table to another if the row
Each time, the figure should move 1/16 of its current distance from the goal
How I can handle map move event by user? (Down left mouse button and
My goal is to override returned UPS rates in the one page checkout, Magento
My goal is to make the Delete key (without any modifiers) move selected files
I need to move a SVN repository from one server to another in Windows.
My goal is to move away from an ISAPI filter that was set up
Goal Build a Circular ViewPager. The first element lets you peak to the last
End Goal: Getting a speedometer style needle to move around a dial according to

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.