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: I want to say: JQuery code: $ ("P"). append ("Hi!"); Result: I want to say:Hi! |
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: I want to say: JQuery code: $ ("Hi!"). AppendTo (" p ") Result: I want to say:Hi! |
Prepend () |
To each matched elementInternalPre-content |
HTML code: I want to say: JQuery code: $ ("P"). prepend ("Hi!") Result: Hi!I want to say: |
PrependTo () |
Forward all matched elements to the specified element. . In fact, this method is reversed. Regular $ (A). prepend (B) operations. |
HTML code: I want to say: JQuery code: $ ("Hi!"). PrependTo (" p ") Result: Hi!I want to say: |
After () |
Insert content after each matching element |
HTML code: I want to say: JQuery code: $ ("P"). after ("Hi!") Result: I want to say: Hi! |
InsertAfter () |
Inserts all matching elements into the specified element. Actually, this method is used. The regular $ (A). after (B) operations are reversed. |
HTML code: I want to say: JQuery code: $ ("Hi!"). InsertAfter (" p ") Result: I want to say: Hi! |
Before () |
Insert content before each matching element |
HTML code: I want to say: JQuery code: $ ("P"). before ("Hi!") Result: Hi! I want to say: |
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: I want to say: JQuery code: $ ("Hi!"). InsertBefore (" p ") Result: Hi! I want to say: |
The above is all the content of this article. I hope you will like it.