Home > Web Front-end > JS Tutorial > jQuery's text() method usage analysis_jquery

jQuery's text() method usage analysis_jquery

WBOY
Release: 2016-05-16 16:25:12
Original
1401 people have browsed it

The example in this article describes the usage of jQuery’s text() method. Share it with everyone for your reference. The specific analysis is as follows:

This method returns or sets the text content of the matching element.
For more information, please refer to the reference manual text() method.

Special instructions:

HTML content means that the content can contain HTML tags and can be rendered by the browser.
The text content is to first convert the HTML predefined characters in the content into HTML character entities, so that the HTML tags will not be rendered.

Usage of text() method:

Usage 1:

When this method takes no parameters, its function is to obtain the text content of all matching elements, and the result is the text combined by the text content contained in all matching elements.

This method is similar to the html() method without parameters, but there are still big differences:

1.html() method obtains the content of the first matching element, while text() method obtains the content contained in all matching elements.
2. The html() method obtains the html content, while the text() method obtains the text content.

The example code is as follows:

Copy code The code is as follows:






text() function-Script Home







  • html area

  • DIV CSS Zone

  • jquery area






The above code can pop up and obtain all the text content in the div.

Usage 2:

With parameters, it sets the text content of all matching elements.
This method is similar to the html() method with parameters, but there are still big differences:
The text() method sets the text content of the matching element, and converts reserved characters in HTML (such as the greater than sign (>)) into html character entities for correct display, while the html() method sets the matching The html content of the element.

Example code:

Copy code The code is as follows:






text() function-Script Home





Original content




Example code three:

Copy code The code is as follows:






text()函数-脚本之家










通过此实例大家可以观察一下HTML内容和文本内容的区别。

希望本文所述对大家的jQuery程序设计有所帮助。

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