JQuery DOM insert node operation guide
This topic describes jQuery's methods for dynamically inserting nodes in HTML. You can create a table to facilitate comparison and learning. For more information, see
Method |
Description |
Example |
Append () |
To each matched elementInternalAppend content |
HTML code: <p> I want to say: </p> JQuery code: $ ("P"). append ("<B> Hello </B> "); Result: <P> I want to say: <B> Hello </B> </p> |
AppendTo () |
Append all matched elements to the specified element. . In fact, this method is used to reverse the General The $ (A). append (B) Operation of is to append A to B. |
HTML code: <p> I want to say: </p> JQuery code: $ ("<B> Hello </B>"). appendTo ("p ") Result: <P> I want to say: <B> Hello </B> </p> |
Prepend () |
To each matched elementInternalPre-content |
HTML code: <p> I want to say: </p> JQuery code: $ ("P"). prepend ("<B> Hello </B> ") Result: <P> <B> Hello </B> I want to say: </p> |
PrependTo () |
Forward all matched elements to the specified element. . In fact, this method is reversed. Regular $ (A). prepend (B) operations. |
HTML code: <p> I want to say: </p> JQuery code: $ ("<B> Hello </B>"). prependTo ("p ") Result: <P> <B> Hello </B> I want to say: </p> |
After () |
Insert content after each Matching Element |
HTML code: <p> I want to say: </p> JQuery code: $ ("P"). after ("<B> Hello </B> ") Result: <P> I want to say: </p> <B> Hello </B> |
InsertAfter () |
Inserts all matching elements into the specified element. Actually, this method is used. The regular $ (A). after (B) operations are reversed. |
HTML code: <p> I want to say: </p> JQuery code: $ ("<B> Hello </B>"). insertAfter ("p ") Result: <P> I want to say: </p> <B> Hello </B> |
Before () |
Insert content before each Matching Element |
HTML code: <p> I want to say: </p> JQuery code: $ ("P"). before ("<B> Hello </B> ") Result: <B> Hello </B> <p> I want to say: </p> |
InsertBefore () |
Insert the matched element to the specified Before the specified element. Actually, This method is used to reverse the General $ (A). before (B. |
HTML code: <p> I want to say: </p> JQuery code: $ ("<B> Hello </B>"). insertBefore ("p ") Result: <B> Hello </B> <p> I want to say: </p> |
The above is all the content of this article. I hope you will like it.