Home > Web Front-end > JS Tutorial > What are the differences between the use of text() val() and html() in jQuery?

What are the differences between the use of text() val() and html() in jQuery?

php中世界最好的语言
Release: 2018-04-23 16:04:57
Original
2424 people have browsed it

This time I will bring you the differences between the use of text() val() and html() in jQuery. What are the precautions for using text() val() and html() in jQuery? There are Which ones, the following are practical cases, let’s take a look.

Simply put: The difference between html() and text() mainly lies in whether tags are included. And val() targets form elements.

But sometimes it’s still not so clear.

html(), val(), and text() are all divided into parameters and no parameters.

Example to illustrate their differences:

html() gets the content of the first matching element without parameters . It must be noted that even if there are multiple matches, only the first matched element can be obtained.

For example:

<p>你选中这段文字后,看看它们的文本颜色和背景色,就能明白::selection的作用。</p>
<h3>选中下面的文字,看看它的颜色</h3>
<h3>选中下面的文字,看看它的颜色</h3>
<h3>选中下面的文字,看看它的颜色</h3>
<input>

Copy after login

The above is the detailed content of What are the differences between the use of text() val() and html() in jQuery?. 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