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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:57:37+00:00 2026-06-15T12:57:37+00:00

I am trying to implement a function which will change the elements order in

  • 0

I am trying to implement a function which will change the elements order in a table. The logic is very easy: Each TR (except the first and the last ones) has a button_up and a button_down. When the user clicks one of those buttons, the element will change his place with the one above or below.

To do this, I am using jQuery and each TR has a unique Id and the buttons have a common class.

When a button with the specific class is clicked, I am executing this JavaScript code:

$('.upArrow').click( function(something)     
        {           
            var id = $(this).attr("id");

            var n=id.split("_");

            var new_id = '#row_'+n[1];

            var parent =$(new_id);
            var prev = $(new_id).prev();

            swap(prev, parent); 

            init_authors_list_ordering();
        });


        $('.downArrow').live('click', function()
        {
             var id = $(this).attr("id");

                var n=id.split("_");

                var new_id = '#row_'+n[1];

                var parent =$(new_id);
                var next = $(new_id).next();

                swap(next, parent); 

                init_authors_list_ordering();
        });
}

function swap(a, b, direction)
{
    var html = a.wrapInner('<tr></tr>').html();
    a.replaceWith(b.wrapInner('<tr></tr>').html());
    b.replaceWith(html);
}

The problem is that: The first time, everything works fine (my funxtion is not finished, I have to set some other parameters on change but the logic is there). But then, The two elements who changed their place have lost the TR’s id, so they can’t be touched anymore.

I don’t know why the id is lost. This is the replaceWith() method.

Any help is welcome. Thank you.

  • 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-15T12:57:39+00:00Added an answer on June 15, 2026 at 12:57 pm

    To swap the elements, simply do:

    function swap(a, direction, b) {
        a[direction](b);
    }
    

    and call like:

    var firstElem  = $('#divID'),
        secondElem = $('#divID');
    
    swap(firstElem, 'before', secondElem); // or after, whatever you need ?
    

    FIDDLE

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

Sidebar

Related Questions

I am trying to implement a generic timer function in OCaml which will take
I'm new to JQuery and trying to implement a function which will hide an
I'm trying to develop a function which will allow me to input new elements
I;m trying yo implement a javacript function which will not allow to the user
I am trying to implement a function called inet_pton which will convert a string
I'm trying to implement a distinctOn function for a sequence which will take a
I'm trying to implement a custom aggregate function in Postgres which will average directions
I am trying to implement a function for my SSRS report which will return
I am trying to figure out exactly how to implement a callback function which
I'm trying to implement a function which would load a server-stored CSV file, and

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.