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.>
String 값의 bold() 메서드는 문자열을 굵게 보이게 하는 <b> 요소(<b>str</b>)에 해당 문자열을 집어넣은 문자열을 생성합니다.
참고 :
모든 HTML 래퍼 메서드는 더 이상 사용되지 않으며 호환성 목적으로만 표준화되었습니다. 대신 document.createElement()와 같은 DOM API를 사용하시기 바랍니다.
구문
js
bold()
Parameters
없음.
반환 값
<b> 시작 태그, 그 다음 str 내용, </b> 종료 태그로 이어지는 문자열.
예제
>bold() 사용하기
아래 코드는 HTML 문자열을 생성한 다음 document의 body를 해당 문자열로 대체합니다.
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);
명세서
| Specification |
|---|
| ECMAScript® 2027 Language Specification> # sec-string.prototype.bold> |