Introduction and application of jquery element control (append element/append content)

Source: Internet
Author: User
Tags ming

First, append elements inside/outside the elementAppend,prepend: Adding to child elements
Before,after: Adding as a sibling element

Html:

<div id= "Content" >  add a piece of news to my back  
JS:

add elements to #content, this is to retire <p> Yao Ming ...</p> as a child element added to #content, if you want to append elements outside the element, you need to use after, so you can put <p> Yao Ming retired ...</p> as a sibling element appended to #content back.


ii. append content to different positions in the element

Html:

<div id= "Content1" style= "border:1px solid red" >  window front bright moon light  
Js:

Third, append content at the beginning of the element

Html:

<div> <div id= "Content" >  add a piece of news to my back  
DST

Iv. appending content at the beginning of different elements

Html:

<div id= "Content" >  add a piece of news to my back  
JS:

Add elements to the #content, this is the <span> is the ground frost </span> as a child element added to the beginning of #content, if you want to add a starting element outside the element, you need to use before, so you can put < Span> is the ground frost </span> as a sibling element appended to #content began


V. Elements containing elements with a specified structure

Warp (HTML)
Specifies an HTML element in the specified HTML, but the specified element cannot contain sibling elements, otherwise it does not run normally and does not contain a generic text string, and the following code contains the P tag with a div tag.

Html:

JS:

Vi. contains multiple HTML elements with the specified element

Wrapall (HTML)

Html:

<form id= "Form1" runat= "Server" > P content P content p content p content     
JS:
<script type= "Text/javascript" > JQuery (Function () {$ ("P"). Wrapall ("<div style= ' border:1px solid red ' >  

Seven, with the specified label contains child elements

Wrapinner (HTML)
As with the Warp method, you specify HTML elements in HTML, such as:
The code with the B tag containing the text in the P tag is as follows:

HTML:

JS:



Introduction and application of jquery element control (append element/append content)

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.