iCode101
iCode101

Reputation: 414

Why does .append() replace table rows when sorting?

Could someone please explain why the .append() method replaces table rows when sorting.

Why doesn't it add the sorted rows to the end of the unsorted rows?

Script

Demo

Upvotes: 2

Views: 87

Answers (2)

dfsq
dfsq

Reputation: 193271

$.fn.append method of jquery is based on native Node.appendChild method. This method inserts node to the end of the parent element it was called on, if new node is not yet in DOM tree. Or otherwise it moves node to new location. So it takes it from where it was previously and inserts to the end of the new parent.

Upvotes: 0

Quentin
Quentin

Reputation: 943661

It does append the row to the end, but since a row can't be in two places at once, it removes it from where ever it was before.

If the sort algorithm would put the first row last then it would:

  1. Remove the first row
  2. Cause the next four rows to move up
  3. Put the previously first row at the end

Upvotes: 1

Related Questions