Home  >  Article  >  Web Front-end  >  A brief analysis of the differences between html(), text() and val() in jquery

A brief analysis of the differences between html(), text() and val() in jquery

不言
不言Original
2018-08-06 16:37:381616browse

This article brings you a brief analysis of the differences between html(), text(), and val() in jquery. It has certain reference value. Friends in need can refer to it. Hope it helps.

.html() is used to read and modify the HTML tags of elements. Corresponding to innerHTML

in js.html() is used to read elements. HTML content (including its Html tag), when the .html() method is used on multiple elements, only the first element is read

.text() is used to read Or modify the plain text content of the element, corresponding to innerText in js

text() is used to read the plain text content of the element, including its descendant elements; the .text() method cannot be used on form elements

.val() Used to read or modify the value of the form element

.val() is used to read the "value" value of the form element, .val( ) can only be used on form elements

Differences between the three

1. The .val() method is the same as .html(). If it is applied to multiple elements, only The "value" value of the first form element can be read, but .text() is different from them. If .text() is applied to multiple elements, the text content of all selected elements will be read.

2.html(),.text(),.val() can all use the return value of the callback function to dynamically change the content of multiple elements.

Recommended related articles:

Summary of font attribute in HTML

js tutorial - Array loop deletion error implementation and solution

The above is the detailed content of A brief analysis of the differences between html(), text() and val() in jquery. For more information, please follow other related articles on the PHP Chinese website!

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