Sort operations such as move up, move down, and so on for an element

Source: Internet
Author: User

In some recent projects, I have often encountered the need to sort elements, including: Move Up, Move down, top, bottom. So how does this work?

Move up, in short, the position of the element that needs to be moved up and its front element, using InsertBefore (), the general idea is:

var dom= the element that needs to be moved up; var domprev=dom.prev ();d om.insertbefore (Domprev);

Move down, similar to move up, will need to move down the element and the element behind it exchange position, using InsertAfter (), the approximate idea is:

var dom= the element that needs to be moved down; var domnext=dom.next ();d om.insertafter (Domnext);

Top, the first child that will need the top element to become its parent element, using Prependto (), the general idea is:

var dom= the element that needs to be pinned, Var domparent=dom.parent ();d om.prependto (domparent), bottom, similar to top, the last child that will need to turn the bottom element into its parent element, using Appendto (), The general idea is:
Var dom= requires a base element, Var domparent=dom.parent ();d om.appendto (domparent), InsertBefore (), InsertAfter (), Prependto (), AppendTo () can implement these simple sorting operations on the element.

Sort operations such as move up, move down, and so on for an element

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.