Home >Web Front-end >JS Tutorial >Usage analysis of append() and appendto() in jquery_jquery

Usage analysis of append() and appendto() in jquery_jquery

WBOY
WBOYOriginal
2016-05-16 16:31:191469browse

This article analyzes the usage of append() and appendto() in jquery with examples. Share it with everyone for your reference. The specific analysis is as follows:

In jQuery's document operation method, the append() and appendto() methods perform the same tasks, but there are also differences between the two.

1. append() method: Insert the specified content at the end of the selected element (but still within the element).

a. Syntax:

Copy code The code is as follows:
$(selector).append(content);
Among them, the parameter content is required, specifying the content to be appended.

b. append can use functions to append content to selected elements. The syntax is:

Copy the code The code is as follows:
$(selector).append(function(index,html));
Among them, function() is required, and the parameters index and html are optional. Index represents the index position of the receiving selector, and html represents the current html of the receiving selector.

Example:

Copy code The code is as follows:






This is a paragraph.


This is another paragraph.




The running results are as follows:

This is a paragraph. Hello jQuery!
This is another paragraph. Hello jQuery!

2. appendto() method: Insert the specified content at the end of the selected element (but still inside the element). But you cannot use functions to append content.

Syntax:

Copy code The code is as follows:
$(content).appendto(selector);

Example:

Copy code The code is as follows:






This is a paragraph.


This is another paragraph.





The running results are as follows:

This is a paragraph. Hello jQuery!
This is another paragraph. Hello jQuery!

I hope this article will be helpful to everyone’s jQuery programming.

Statement:
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