--- id: 564944c91be2204b269d51e3 title: jQuery を使用して要素の内側のテキストを変更する challengeType: 6 forumTopicId: 16773 dashedName: change-text-inside-an-element-using-jquery --- # --description-- jQuery を使用して、要素の開始タグと終了タグの間にあるテキストを変更できます。 HTML のマークアップを変更することもできます。 jQuery には `.html()` という関数があり、要素内に HTML タグとテキストを追加できます。 すでに要素内にある内容はすべて、この関数を使用して提供する内容に完全に置き換えられます。 見出しのテキストを書き換えて強調表示する方法を次に示します。 ```js $("h3").html("jQuery Playground"); ``` jQuery には `.text()` という同様の関数もあります。この関数は、タグを追加せずにテキストのみを変更します。 つまり、この関数は渡された HTML タグを評価せず、既存の内容を置き換える対象のテキストとして扱います。 id が `target4` のボタンを変更して、テキストを強調表示してください。 `` と `` の違いとそれらの用例については、[<em> についてのニュース記事](https://www.freecodecamp.org/news/html-elements-explained-what-are-html-tags/#em-element)を参照してください。 `` タグは従来からテキストの強調に使用されていますが、最近ではアイコンのタグとして採用されています。 `` タグは現在、強調用のタグとして広く使用されています。 このチャレンジではどちらも正しく機能します。 # --hints-- HTML タグを追加して、`target4` ボタンのテキストを強調表示します。 ```js assert.isTrue( /|\s*#target4\s*<\/em>|<\/i>/gi.test($('#target4').html()) ); ``` それ以外はテキストに変更を加えません。 ```js assert($('#target4') && $('#target4').text().trim() === '#target4'); ``` 他のテキストは変更しません。 ```js assert.isFalse(/|/gi.test($('h3').html())); ``` `.text()` ではなく `.html()` を使用してください。 ```js assert(code.match(/\.html\(/g)); ``` jQuery を使用して `button id="target4"` を選択します。 ```js assert(code.match(/\$\(\s*?(\"|\')#target4(\"|\')\s*?\)\.html\(/)); ``` # --seed-- ## --seed-contents-- ```html jQuery Playground #left-well #target1 #target2 #target3 #right-well #target4 #target5 #target6 ``` # --solutions-- ```html jQuery Playground #left-well #target1 #target2 #target3 #right-well #target4 #target5 #target6 ```