Introduction to node operations in jQuery _ jquery-js tutorial

Source: Internet
Author: User
In this article, I will introduce you to some suggestions on how to operate nodes in jQuery. If you need them, you can refer to the dynamic creation of Dom nodes.

In jQuery, $ (html string) is used to dynamically create Dom nodes and a jQuery object is returned. You can call the append method to add the created nodes to the Dom.

For example:

Var link = $ ("Baidu ");

$ ("P: first"). append (link );

Add a node element:

The Append method is used to Append an element (the last subnode) to the end of an element)

Prepend add an element (first subnode) at the beginning of the element)

After: add an element (add a sibling node) After the element)

Before: add an element Before the element (add a sibling node)

Child element. appendTo (parent element): append a child element to the end of the element.

Child element. prependTo (parent element): append a child element at the beginning of the element.

A. insertBefore (B) inserts A before B, equivalent to B. before ();

X. insertAfter (B) inserts X after Y, which is equivalent to Y. after (X );

Delete a node:

Empty (): clears all subnodes under this element.

Equivalent to: while (ele. firstChild) {ele. removeChild (ele. firstChild );}

Remove (selectot); stop; Delete the current element. The returned value is the deleted element. You can say that the deleted node is placed under another node and has a moving effect, for example:

Var lis = $ ("# ulSite li"). remove ();

$ ("# UlSite2"). append (lis );


Clone (): Clone a node, supporting a replication node. Do not copy a node.

Clone (true): Clone node with event


Node replacement:

$ ("Br"). replaceWith ("

");

$ ("Br"). replaceAll ("

");

Package Node

The Wrap () method is used to Wrap all elements one by one with the specified label.

$ ("B"). wrap (""); show all bold characters in red

WrapInner ();

Related Article

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.