The four JQuery methods for adding new content are the following:
Append ()-inserts content at the end of the selected element ( inside )
Prepend ()-Inserts content at the beginning of the selected element ( inside )
// The jQuery Append () method inserts the content at the end of the selected element. $ ("P"). Append ("Some appended text." ); // The jQuery prepend () method inserts content at the beginning of the selected element. $ ("P"). Prepend ("Some prepended text.");
Adding several new elements through the Append () and prepend () methods
function AppendText () {var txt1= "<p>Text.</p>"; // Create new elements in HTML var txt2=$ ("<p></p>"). Text ("text."); // Create a new element in JQuery var txt3=document.createelement ("P"); // Create a new element in DOM txt3.innerhtml= "Text." ; $ ("P"). Append (TXT1,TXT2,TXT3); // Append new Element }
After ()-Inserts content after the selected element ( outside )
Before ()-insert content before the selected element ( outside )
$ ("img"). After ("Some text after"); $ ("IMG"). Before ("Some text before");
Adding several new elements through the After () and before () methods
function Aftertext () {var txt1= "<b>i </b>"; // Create new elements in HTML var txt2=$ ("<i></i>"). Text ("Love"); // Create new elements with JQuery var txt3=document.createelement ("big"); // Create a new element from the DOM txt3.innerhtml= "jquery!" ; $ ("IMG"). After (TXT1,TXT2,TXT3); // Insert new element after IMG }
Four jQuery methods for adding new content: Append,prepend,after,before