jquery Add and remove elements

Source: Internet
Author: User

Add a new HTML content

We'll learn the four jQuery methods for adding new content:

  • Append ()-inserts content at the end of the selected element
  • Prepend ()-Inserts content at the beginning of the selected element
  • After ()-Inserts the content after the selected element
  • Before ()-insert content before selected element
    1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "Utf-8">5 <Scriptsrc= "Https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">6 </Script>7 <Script>8 $ (document). Ready (function(){9     varI= 0;Ten   $("#btn1"). Click (function(){ One I++ ; A     $("P"). Append ("<b>" +I+ "</b>" + "   "); -   }); -  the   $("#btn2"). Click (function(){ -     $("ol"). Append ("<li> Add a list </li>"); -   }); - }); + </Script> - </Head> +  A <Body> at <P>Number:</P> - <ol> - <Li>List Item 1</Li> - <Li>List Item 2</Li> - <Li>List Item 3</Li> - </ol> in <ButtonID= "BTN1">Add text numbers</Button> - <ButtonID= "BTN2">Add List item</Button> to <HR> + <Buttononclick= "AppendText ()">Append text</Button> - </Body> the  * <Script> $ functionAppendText () {Panax Notoginseng     vartxt1="<b> text------</b>"; //Create text using HTML tags -     vartxt2=$("<u></u>"). Text ("Text-----"); //Create text using JQuery the     varTxt3=Document.createelement ("I"); + txt3.innerhtml="text. "; //using the DOM to create text with Dom A     $("Body"). Append (TXT1,TXT2,TXT3); //Append new Element the } + </Script> - </HTML>

jquery Add and remove elements

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.