The AppendTo () method inserts the specified content at the end of the selected element (still inside).
Tip: The Append () and AppendTo () methods perform the same tasks. The difference is that the location of content and selectors, and append () can use functions to attach content.
AppendTo () method code shows:
1 <HTML>2 <Head>3 <Scripttype= "Text/javascript"src= "/jquery/jquery.js"></Script>4 <Scripttype= "Text/javascript">5 $ (document). Ready (function(){6 $("Button"). Click (function(){7 $ ("<b> Hello world!</b>"). AppendTo ("p ");8 });9 });Ten </Script> One </Head> A <Body> - <P>This is a paragraph.</P> - <P>This is another paragraph.</P> the <Button>Add content at the end of each P element</Button> - </Body> - </HTML>
The effect is as follows:
AppendTo () method code shows:
1 <HTML>2 <Head>3 <Scripttype= "Text/javascript"src= "/jquery/jquery.js"></Script>4 <Scripttype= "Text/javascript">5 $ (document). Ready (function(){6 $("Button"). Click (function(){7 $ ("P"). Append ( " <b>hello world!</b> ");8 });9 });Ten </Script> One </Head> A <Body> - <P>This is a paragraph.</P> - <P>This is another paragraph.</P> the <Button>Add content at the end of each P element</Button> - </Body> - </HTML>
The effect is as follows:
Description: The Append () method inserts the specified content at the end of the selected element (still inside).
1 <HTML>2 <Head>3 <Scripttype= "Text/javascript"src= "/jquery/jquery.js"></Script>4 <Scripttype= "Text/javascript">5 $ (document). Ready (function(){6 $("Button"). Click (function(){7 $("P"). Append (function(n) {8return "<b>this P element has index" +N+ "</b>";9 });Ten }); One }); A </Script> - </Head> - the <Body> - <H1>Assad French red wine happy</H1> - <P>Assad French red wine happy</P> - <P>Assad French red wine happy</P> + <Button>Add content at the end of each P element</Button> - </Body> + </HTML>
The effect is as follows: