J-query Development Brocade (3): AppendTo () method and append () method

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.