1

To sort the results , I am using the below code for swapping two arrays of results in javascript. But its not working in firefox and chrome browser but works only in IE.

for (x=0; x<resultArr.length; x++) {    
        allTR[x].swapNode(colArr[resultArr[x]])
    }

Without using swapNode function, how can I swap two arrays. Here allTR is my parent array as well as target array. whatever temp variables I can have, finally I should append it to allTR array. Please help me this issue

Priya Viji
  • 39
  • 1
  • 10
  • 2
    `swapNode` is a "helpful" IE customisation - it simply doesn't exist in other browsers. [This question](http://stackoverflow.com/questions/2943140/how-to-swap-html-elements-in-javascript) may provide an answer. – James Thorpe Feb 19 '15 at 16:57
  • @JamesThorpe Can you plz give me a snippet to solve my problem – Priya Viji Feb 19 '15 at 17:09
  • 2
    No - that's not how Stack Overflow works. I suggest you research a bit more about DOM manipulation - the question I linked to has several answers doing various things, if none of those work for you, or don't point you in the right direction with additional searches, perhaps edit your question to include reasons why they don't work. – James Thorpe Feb 19 '15 at 17:12

2 Answers2

1

That's very easy in standard JavaScript:

Consider you want to swap two siblings a and b , then code will be as follows:

a.parentNode.insertBefore(b,a)

In your case code will be, allTR[x].parentnode.insertBefore(colArr[resultArr[x]],allTR[x])

Abhay
  • 3,151
  • 1
  • 19
  • 29
0
For **java Script** the solution is for swapping item(row to be moved),previous 
**MoveUp** :
document.getElementById("item").parentNode.insertBefore(document.getElementById("item"),document.getElementById("previous"));

**MoveDown**: 

document.getElementById("item").parentNode.insertBefore(document.getElementById("next"),document.getElementById("item"));

**Jquery:
MoveUp:**

$(function(){
$("upRowId").click(function(event){
var itemRow="";
button_choice=$(this).attr('id');
$(":radio").each(function(){
if(this.checked){
itemRow=$this.closest('tr');
if(button_choice=="upRowId"){
itemRow.insertBefore(itemRow.prev());
    }
   }
  });
 });
});

**MoveDown:**

$(function(){
$("downRowId").click(function(event){
var itemRow="";
button_choice=$(this).attr('id');
$(":radio").each(function(){if(this.checked){
itemRow=$this.closest('tr');
if(button_choice=="downRowId"){
itemRow.insertAfter(itemRow.next());
}
}
});
});
});