String.prototype.bold()
Deprecated
Avoid using this feature in new projects. HTML wrapper methods exist only for backwards compatibility. Use DOM APIs to create elements instead. This feature may be a candidate for removal from web standards or browsers.>
Consider using the following features instead: DOM.>
bold() は String 値のメソッドで、この文字列を <b> 要素に埋め込んだ文字列 (<b>str</b>) を生成し、この文字列が太字で表示されるようにします。
メモ:
HTML ラッパーメソッドはすべて非推奨となっており、互換性目的のみで標準化されています。代わりに DOM API の document.createElement() などを使用してください。
構文
js
bold()
引数
なし。
返値
<b> 開始タグで始まり、str のテキストが来て、 </b> 終了タグが来る文字列です。
例
>bold() の使用
次の例では、非推奨の文字列メソッドを使用して文字列の書式を変更しています。
js
const contentString = "Hello, world";
document.body.innerHTML = contentString.bold();
これにより、次の HTML が生成されます。
html
<b>Hello, world</b>
bold() を使用して HTML テキストを直接作成する代わりに、document.createElement() などの DOM API を使用しましょう。例を示します。
js
const contentString = "Hello, world";
const elem = document.createElement("b");
elem.innerText = contentString;
document.body.appendChild(elem);
仕様書
| 仕様書 |
|---|
| ECMAScript® 2027 Language Specification> # sec-string.prototype.bold> |