Home > Web Front-end > JS Tutorial > body text

jquery append and appendTo usage analysis

小云云
Release: 2018-01-10 13:51:58
Original
2234 people have browsed it

This article mainly introduces relevant information on the difference between jquery append and appendTo methods. Friends who need it can refer to it. I hope it can help everyone.

The difference between append and appendTo methods in jquery

1. append(content) method

Method function:To each Appends content inside the matching element.

Parameter introduction: content (): The content to be appended to the target.

Usage example:

HTML code is

I come from

I love

Append a word china to all p tags, the writing method is $("p").append("china");

The result is:

I come from chinaI love china

2. appendTo(expr) method

Method function:Append all matching elements into the specified collection of elements.

Parameter introduction: expr (String): jQuery expression used to match elements.

Usage example:

HTML code isI love china

Append tag b to p element, written as $("b").appendTo("p");

The result is:>

I love china < /b>

Using the appendTo method reverses the conventional $(A).append(B) operation, that is, instead of appending B to A, appending A to B in.

Related recommendations:

Problems in using the Jquery append method

jquery insertBefore(), insertAfter(), Detailed explanation of prependTo(), appendTo() usage

The difference between jquery append() method and html() method and introduction to their use

The above is the detailed content of jquery append and appendTo usage analysis. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template