This article mainly introduces JQuery's method for encapsulating DOM nodes. The example analyzes the techniques and precautions for using the wrap and wrapAll methods to wrap DOM nodes, for more information about how to wrap DOM nodes in JQuery, see the example in this article. Share it with you for your reference. The specific analysis is as follows:
If you want to wrap a node with other tags, JQuery provides the corresponding method, namely, wrap (), which is very useful for inserting additional structured tags in the document, and it does not break the semantics of the original document.
Wrap ()
The code is as follows:
$ ("# Li_1"). wrap ("");
The result is as follows:
Simple PHP programming
The package node operation has two other methods: wrapAll () and wrapInner ().
WrapAll () method
This method will wrap all matching elements with one element. Unlike the wrap () method, The wrap () method packages all elements separately. The JQuery code is as follows:
The code is as follows:
$ (". Li_2"). wrapAll ("");
The HTML wrapped in the wrapAll () method is as follows:
Easy-to-understand C Programming Simple and easy-to-understand JavaScript programming
WrapInner () method
This method wraps the child content (including text nodes) of each matching element with other structured tags.
The code is as follows:
$ ("# Li_4"). wrapInner ("");
After running the codeThe content in the tag is a pair
The result is as follows: Simple and easy-to-understand JQuery programmingThe JQuery code in this example is as follows: