The DOM node to create //DOM node to create and write HTML structure is the same of Create the element node: $(" & lt; Div>
" ) Create a text node: $(" & lt; Div> Text nodes & lt;/div>" ) Create an attribute node: $(" & lt; Div id="text" & gt; Text nodes & lt;/div>" )
Internal inserted into the DOM node Hypothesis: & lt; body>
Append (content | fn) and appendTo (content) : at the end of the matching element position insert content Append () : add content to the inside of every matched element, the operation and carry out the appendChild method specified elements, will they add Added to the document in the case of similar, Example: $(" # demo "). Append (" & lt; P> Paragraph tags & lt;/p>" ); AppendTo () : all of the matched elements added to another in a specified element in the collection of elements, in fact, the use of this method is upside down often Rules of $(A). Append (B) the operation, that is not in the B appended to A, but in the appended to the B Example: $(" & lt; P> Paragraph tags & lt;/p>" ). AppendTo ($(" # demo "));
Summary: append () and appendTo () function is the same, two methods of main difference is that grammar, content and the location of the object is different, Append () is inserted in front of the object, the back is to insert in the object element content AppendTo () is to be inserted in front of the element content, the object is being inserted behind
The prepend (content) and prependTo (content) : in the beginning of the matched elements position insert content The prepend () : prepend content to the inside of every matched element. This is to insert elements inside, at the beginning, of all matched elements in the best way, Example: $(" # demo "). The prepend (" & lt; P> Paragraph tags & lt;/p>" ); PrependTo () : all of the matched elements lead to another, specified element in the collection of elements, in fact, the use of this method is upside down Regular $(A). The prepend (B) operation, which is not the B to A in front, and it put A lead to B, Example: $(" & lt; P> Paragraph tags & lt;/p>" ). PrependTo ($(" # demo "));
External inserted into the DOM node Hypothesis: & lt; body>
//description: the content is inserted into the content after each of the target function function must return an HTML string, After (content | fn) and before (the content | fn) After () : insert content at the back of each of the matched elements, Example: $(" # demo ".) after (" & lt; P> Paragraph tags & lt;/p>" ); Before () : insert content before each of the matched elements, Example: $(" # demo "). Before (" & lt; P> Paragraph tags & lt;/p>" );
//description: the content for the jQuery expression of the matched elements InsertAfter (content) and the insertBefore (content) InsertAfter () : insert all of the matched elements to another, specified elements set behind, in fact, the use of this method is Upside down regular $(A). After operation (B), which is not the B is inserted into A behind, but behind the inserted into the B, Example: $(" & lt; P> Paragraph tags & lt;/p>" ). InsertAfter ($(" # demo ")); The insertBefore () : insert all of the matched elements to another, the specified element in the front of the set, in fact, using this method is Upside down regular $(A). After operation (B), which is not the B is inserted into A behind, but behind the inserted into the B, Example: $(" & lt; P> Paragraph tags & lt;/p>" ). The insertBefore ($(" # demo "));
DOM node delete empty (), remove () and detach () The empty () : removes all child nodes from the set of matched elements, Remove ([expr]) : delete all of the matched elements from the DOM, parameter description: expr for jQuery expression of filter element
Difference between the empty () and remove () : Empty () : strictly speaking, the empty () method is not delete nodes, but empty nodes, it can clear all descendants of the element node, the empty Can't delete itself this node Remove () : the node, the node contains all offspring node will be deleted at the same time, provide a filter expression, delete the specified The elements in the collection of
Detach () : this method does not put the matching element is removed from the jQuery object, which can be used again in the future of the matched elements, and Remove (), all bound events, such as additional data will be preserved, $(" div "). The detach () this sentence Would remove object, only without the display effect, but there is a memory, when you append, back on The document flow, then display,