jquery Creating DOM Nodes

Source: Internet
Author: User

1. Creating ELEMENT nodes

The $ (HTML) method creates a DOM element based on the incoming HTML tag string, and replaces the DOM with a jquery object return.
New element nodes that are added dynamically are not automatically added to the document.
When creating a single element, pay attention to closing the label and using the standard XHTML format. such as $ ("<p></p>") $ ("<p/>").

2. Create a text node

Write the text content into $ ("<p>append content </p>") directly when creating the element node.

3. Create attribute Nodes

Creating an attribute node is similar to creating a text node.

Now that you have a node to create, then you need to manipulate the node and sort out the usual: Insert node, delete node, copy node, replace node, wrap node

  jquery Insert Node

1. Append () Inserts content into each matching element

2, AppendTo () appends the content to the specified element reversed the append operation

3. Prepend () Inserts the content into front of each matching element

4. Prependto () to pre-position the content in the specified element

5. After () insert content after each matching element

6, InsertAfter () append content to the specified element

7. Before () Insert content before each matching element

8, InsertBefore () append content to the specified element

jquery Delete Node

1. Remove () method: Removes all matching elements from the DOM. The value returned by this method is a reference to the node being deleted.

2, Detach () method: Removes all matching elements from the DOM. Unlike the Remove () method: The Detach () method preserves all bound events.

3. Empty () Method: Empties the contents of the node.

Replication nodes

1. Clone () Method: Generates a copy of the selected element, including child nodes, attributes, and text.

  Replace node

1, ReplaceWith () replaces all matching elements with the specified XHTML or DOM elements.

2, ReplaceAll () replaces the specified XHTML or DOM element with the matching element.

  Parcel nodes

1. Wrap () Wraps a node with another tag. This method is useful for inserting additional structured markup into a document without destroying the semantics of the original document.

2. Wrapall () wraps all matching elements together with one element Note: If there are other elements between multiple elements of the package, the other elements will be placed after the wrapping element.

3. Wrapinner () wraps the child contents of the matched element with other tags.

  

jquery Creating DOM Nodes

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.