--- id: 564944c91be2204b269d51e3 title: Change Text Inside an Element Using jQuery challengeType: 6 videoUrl: '' localeTitle: 使用jQuery更改元素内的文本 --- ## Description
使用jQuery,您可以更改元素的开始和结束标记之间的文本。您甚至可以更改HTML标记。 jQuery有一个名为.html()的函数,它允许您在元素中添加HTML标记和文本。之前在元素中的任何内容都将完全替换为您使用此功能提供的内容。以下是重写和强调标题文本的方法: $("h3").html("<em>jQuery Playground</em>"); jQuery也有一个类似的函数.text() ,它只改变文本而不添加标签。换句话说,此函数不会评估传递给它的任何HTML标记,而是将其视为要替换现有内容的文本。通过强调其文本来更改id为target4的按钮。查看此链接以了解有关<i><em>之间的区别及其用途的更多信息。请注意,虽然<i>标签传统上一直用于强调文本,但它已被合并用作图标标签。 <em>标签现在被广泛接受为强调标签。两者都可以应对这一挑战。
## Instructions
## Tests
```yml tests: - text: 通过添加HTML标记强调target4按钮中的文本。 testString: 'assert.isTrue((/|\s*#target4\s*<\/em>|<\/i>/gi).test($("#target4").html()), "Emphasize the text in your target4 button by adding HTML tags.");' - text: 确保文本不变。 testString: 'assert($("#target4") && $("#target4").text().trim() === "#target4", "Make sure the text is otherwise unchanged.");' - text: 不要改变任何其他文字。 testString: 'assert.isFalse((/|/gi).test($("h3").html()), "Do not alter any other text.");' - text: 确保使用.html()而不是.text() 。 testString: 'assert(code.match(/\.html\(/g), "Make sure you are using .html() and not .text().");' - text: 确保使用jQuery选择button id="target4" 。 testString: 'assert(code.match(/\$\(\s*?(\"|\")#target4(\"|\")\s*?\)\.html\(/), "Make sure to select button id="target4" with jQuery.");' ```
## Challenge Seed
```html

jQuery Playground

#left-well

#right-well

```
## Solution
```js // solution required ```