jquery-Document Processing

Source: Internet
Author: User

Document processing: Including internal inserts, external inserts, replacements, deletions, replication, etc.

One: Internal insert

use description example
  • Append (content|fn)
append content to each matching element
  $ ("P"). Append ("<b>Hello</b>");  
  • appendTo (content)

Method is reversed for general $ (A). Append (B) operation,

Instead of appending B to a, append a to the B

  $ ("P"). AppendTo ("div");  
  • prepend (CONTENT|FN)
  forward content to each matching element &NB Sp
  $ ("P"). Prepend ("<b>Hello</b>");  
  • prependto (content)

  reversed the operation of General $ (A). prepend (B),

That is, instead of putting B in front of a, place a forward to B

 
  $ ("P"). Prependto ("#foo");  

Two: External insertion

Use Description Example
  • After (CONTENT|FN)
Insert content after each matching element
$("p").after("<b>Hello</b>");
  • Before (CONTENT|FN)
Insert content before each matching element
$("p").before("<b>Hello</b>");
  • InsertAfter (content)

$ (A). After (B) operation,

Which is not to insert B behind a,

Instead, insert a into the back of B.

  • InsertBefore (content)

$ (A). Before (B) operation,

That is, instead of inserting b in front of a,

Instead, insert a into front of B.

Three: Replace

Use Description Example
  • ReplaceWith (CONTENT|FN)
Replaces all matching elements with the specified HTML or DOM element
$("p").replaceWith("<b>Paragraph. </b>");
  • ReplaceAll (selector)
Replace all selector matched elements with matching elements
$("<b>Paragraph. </b>").replaceAll("p");

Four: Delete

Use Description Example
  • Empty ()
Delete all child nodes in the matching element collection
$("p").empty();
  • Remove ([expr])
Remove all matching elements from the DOM
$("p").remove();

V: Cloning

Use Description Example
  • Clone ([Even[,deepeven]])
Clones matching DOM elements and selects copies of these clones
$("b").clone().prependTo("p");

jquery-Document Processing

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.