Dom operations in jquery

Source: Internet
Author: User

1. Finding nodes

Use the jquery selector to complete

1.1 Finding ELEMENT nodes

$ ("ul Li:eq (1)")

1.2 Finding attribute Nodes

var $para = $ ("P");

var p_txt = $para. attr ("title");

2. Create a Node

2.1 Creating an Element node

var $li _1 = $ ("<li></li>");

$ ("ul"). Append ($li _1);

2.2 Creating a text node

var $li _1 = $ ("<li> banana </li>");

$ ("ul"). Append ($li _1);

2.3 Creating an Attribute node

var $li _1 = $ ("<li title= ' banana ' > Banana </li>");

$ ("ul"). Append ($li _1);

3. Inserting nodes

Methods for inserting nodes

Append (): Append content to each matching element

AppendTo (): Appends all matching elements to the specified element

Prepend (): front content to each matched element

Prependto (): Place all matching elements in front of the specified element

After (): Insert content after each element

InsertAfter (): After () opposite

Before (): Insert content before each matching element

InsertBefore (): Before () instead

4. Delete a node

4.1 Remove method

$ ("ul Li:eq (1)"). Remove ();

$ ("ul Li"). Remove ("li[title!= pineapple");

4.2 Empty method

$ ("ul Li:eq (1))"). empty ();

5. Copying nodes

$ ("ul Li"). Click (function () {

$ (this). Clone (). AppendTo ("ul");

})

$ (this). Clone (True). AppendTo ("body"); Adds true to make the copied new element have the original behavior

¥ (This). AppendTo ("body"); Mobile Node

6. Replacing nodes

$ ("P"). ReplaceWith ("<strong>text</strong>");

$ ("<strong>text</strong"). ReplaceAll ("P");

7. Parcel Nodes

$ ("strong"). Wrap ("<b></b>"); Separate packages for all elements

$ ("strong"). Wrapall ("<b></b>"); Wrap all matching elements with one element

$ ("strong"). Wrapinner ("<b></b>"); Wraps the child content of each matching element (including the text node) with other structured tags.

  

Dom operations in jquery

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.