A Pen by Bre'Ana Deen on CodePen.
Modify the example above so that it moves the fourth element from the first list, and places it as the first list item in the second list.
<ul id="yours"> | |
<li>First</li> | |
<li>Second</li> | |
<li>Third</li> | |
<li>Fourth</li> | |
</ul> | |
<ul id="mine"> | |
<li>First</li> | |
<li>Second</li> | |
<li>Third</li> | |
</ul> | |
A Pen by Bre'Ana Deen on CodePen.
Modify the example above so that it moves the fourth element from the first list, and places it as the first list item in the second list.
var list1 = document.getElementById("yours"); | |
var list2 = document.getElementById("mine"); | |
var item = list1.children[3]; // obtain the fourth element from the first list | |
listItems = list2.children; | |
list2.insertBefore(item, listItems[0]); |