0

If I have a form with 5 children elements, is there a way to swap, for example, the second one and the 4th one via that pseudo array children of the form? Like:

let temp = parent_form.children[1st_swapped_elem_index];
parent_form.children[1st_swapped_elem_index] =       parent_form.children[2nd_swapped_elem_index];
parent_form.children[1st_swapped_elem_index] = temp;

But it doesnt work, nothing happens. As the 1st_swapped_elem_index and 2nd_swapped_elem_index there are legal, usable and defined variables, each of them holds a certain DOM element.

Alex Buddy
  • 473
  • 1
  • 6
  • 15
  • What is the actual problem your trying to solve? The way items are displayed in a list to the user? The iteration order using `forEach`/`for` loop? – Jared Smith Apr 07 '16 at 15:55
  • 1
    The problem is - there are few input intems, I want to make simple todo list with HTML5 drag and drop API, and when I drop the dragged item on some other, they are supposed to switch their positions on the screen. So I am trying to use that piece of code to change their positions in the children array-ish and I'm hoping a browser would render them on the new places. But they dont switch places in the children. The console doesn't log any errors though, the temp value gets the 1st_swapped_elem, but it doesn't swap them in the html collection – Alex Buddy Apr 07 '16 at 16:03
  • https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Drag_operations – Jared Smith Apr 07 '16 at 16:05
  • No there is no loop, I just wrote the items dowm in index.html – Alex Buddy Apr 07 '16 at 16:05
  • I couldn't do it via append child or insertBefore – Alex Buddy Apr 07 '16 at 16:07
  • I tried but I gave up on it after some time – Alex Buddy Apr 07 '16 at 16:07
  • Possible duplicate of [Drag and drop to reorder HTML lists](http://stackoverflow.com/questions/10361779/drag-and-drop-to-reorder-html-lists) – Jared Smith Apr 07 '16 at 16:20

0 Answers0