Home>Article>Web Front-end> How to change the content of
Two modification methods: 1. Use the jquery selector to obtain the h tag object, and use text() to modify the text content of the object. The syntax is "$("selector").text("new content") ;"; 2. Use the jquery selector to obtain the h tag object, and use html() to modify the content of the object (the content of the text and HTML tag), with the syntax "$("selector").html("new content"); ".
The operating environment of this tutorial: windows7 system, jquery3.6.1 version, Dell G3 computer.
Two ways to change the content of the
Method 1: Use text() to change the text content
text() can set the text content of the element, which can be changed by simply setting the text content to a new value.
Modification steps:
Use jquery selector to obtain the h tag (h1~h6) object
$("选择器")
Use text() to modify the content of the obtained object
对象.text("新内容")
Example:
这是一个大标题。
这是另一个标题。
这是另一个标题。
这是另一个段落。
Method 2: Use html() changes tag content
html() can set or return content that contains text and HTML tags.
Modification steps:
Use jquery selector to obtain the h tag (h1~h6) object
$("选择器")
Use html() to modify the content of the obtained object
对象.html("新内容")
Example:
这是一个大标题。
这是另一个标题。
这是另一个标题。
这是另一个段落。
Expand knowledge: html () Comparison with text()
html() obtains all the content inside the element, while text() obtains only the text content.
PHP中文网
html()是:
text()是:
The difference between the two methods html() and text() can be clearly compared from the following table.
HTML code | html() | text() |
---|---|---|
PHP Chinese website | PHP Chinese website | |
##PHP中文网 | PHP中文网 | |
(empty string) |
The above is the detailed content of How to change the content of