JQuery DOM Operations-copy nodes, replace nodes, wrap nodes

Source: Internet
Author: User

Clone ():

Copy node, no event by default, if a parameter true is passed, the event that is bound in the element is copied while the node is being copied.

1 <Scripttype= "Text/javascript">2     $(function(){3         var$apple= $("ul li:eq (0)"). Clone ();4         $("ul"). Append ($apple);5     });6 </Script>

ReplaceWith ():

Replaces all matching elements with the specified HTML or DOM element.

1 <Scripttype= "Text/javascript">2     $(function(){3         $("ul Li"). each (function(){4             $( This). ReplaceWith ("<li title= '"+ $( This). attr ("title")+"' style= ' background-color: #f00; ' >"+$( This). Text ()+"</li>");5         });6     });7 </Script>

ReplaceAll ():

Replace all matching elements with HTML or DOM elements.

1 <Scripttype= "Text/javascript">2     $(function(){3         $("<li title= ' Apple ' >Apple</li>"). ReplaceAll ("ul li:eq (0)");4     });5 </Script>

Note: If you replace an event with an element that was previously bound, the event will disappear after the substitution and the event needs to be re-bound.

Wrap ():

Use tags to wrap the matching nodes together.

Wrapall ():

Use tags to package all the nodes that match.

Note: If there are other elements between multiple elements that are contained, the other elements are placed after the wrapping element.

Wrapinner ():

Use tags to wrap the child elements of the matching node.

JQuery DOM Operations-copy nodes, replace nodes, wrap 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.