String.prototype.bold()

지원이 중단되었습니다: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

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 Language Specification
# sec-string.prototype.bold

브라우저 호환성

BCD tables only load in the browser

같이 보기