What and why do we use "ol.insertBefore(li, prevLi);" & "ol.insertBefore(nextLi, li);" for UP and DOWN button.??
What and why do we use "ol.insertBefore(li, prevLi);" & "ol.insertBefore(nextLi, li);" for UP and DOWN button.?? I couldnt get the concept. Can anyone explain in detail please..!
Steven Parker182,617 Points
In both cases, the code is changing the order of the items in the ordered list. The arguments specify the item that is being moved, and a reference item that it will be placed in front of.
In the second case, the intended result is to position the target item after another one, and since there is no "insertAfter" method, the arguments are simply reversed.
I still dont understand the explanation. In both cases insertBefore changes items in the list. I 'UP' case change with element that is above (previousElementSibling) and id 'DOWN' case change it's place with item that is bottom (nextElementSibling). So why those 'li' element changes its places in insertBefore?
Thanks a lot, Steven, now It seems much more clear.