JavaScript

[DOM_Style] JS - fontWeight 속성 - 글자굵기 (= font-weight속성 = 폰트굵기 = 글씨체굵기 =글씨굵기 = 글자굵기 = 글씨두께 = 글자두께 = 서체굵기=글꼴굵기 = 폰트웨이트속성, 상속 O) ※ 폰트/글자 긁게

목차

  1. fontWeight 예제 - 글자 굵기 설정
  2. fontWeight 정의
  3. fontWeight 구문
  4. fontWeight 예제 - 글자 굵기 선택 메뉴
  5. fontWeight 예제 - 글자 굵기 반환
  6. fontWeight 예제 - 클릭 시 글자 굵게

 

fontWeight 예제 - 글자 굵기 설정

 

<p id="hz">홈짱닷컴 Homzzang.com</p>


<button type="button" onclick="homzzang()">클릭</button>

 

<script>

function homzzang() {

  document.getElementById("hz").style.fontWeight = "900";

}

</script>

 

결과보기

 

fontWeight 정의

 

글자(텍스트) 굵기 설정/반환.

 


 

1.

  • 기본값: normal
  • 반환값: 텍스트 굵기 나타내는 문자열.
  • CSS속성: font-weight
  • CSS버전: CSS1


2.

모든 브라우저 지원. 

 

 

fontWeight 구문

 

글자 굵기 반환 

object.style.fontWeight

 

글자 굵기 설정

object.style.fontWeight = "normal|lighter|bold|bolder|100~900|initial|inherit"

 


[속성값]

 

normal 
기본 굵기 (기본값) (= 400)
 
bold
굵은 서체 (= 700)
 
bolder 
상속된 굵기보다 더 굵은 서체
 
lighter 
상속된 굵기보다 더 얇은 서체
 
100 200 300 400 500 600 700 800 900 
얇음  ←   굵기   →  굵음  (※ 100 단위로 900까지 가능)
 
initial
이 속성의 기본값으로 설정.
 
inherit 

부모 요소의 굵기를 상속 

 

 

fontWeight 예제 - 글자 굵기 선택 메뉴

 

<p id="hz">홈짱닷컴 Homzzang.com</p>


<select onchange="homzzang(this);" size="13">

  <option>normal</option>

  <option>bold</option>

  <option>bolder</option>

  <option>lighter</option>

  <option>100</option>

  <option>200</option>

  <option>300</option>

  <option>400</option>

  <option>500</option>

  <option>600</option>

  <option>700</option>

  <option>800</option>

  <option>900</option>

</select>

 

<script>

function homzzang(sel) {

  var sizeValue = sel.options[sel.selectedIndex].text;

  document.getElementById("hz").style.fontWeight = sizeValue;

}

</script>

 

결과보기

 

fontWeight 예제 - 글자 굵기 반환

 

<p id="hz" style="font-weight:bold">홈짱닷컴 Homzzang.com</p>


<button type="button" onclick="homzzang()">클릭</button>

 

<script>

function homzzang() {

  var sizeValue = document.getElementById("hz").style.fontWeight;

  alert(sizeValue);

}

</script>

 

결과보기

 

fontWeight 예제 - 클릭 시 글자 굵게

 

<span onclick=style.fontWeight='bold'>홈짱닷컴 Homzzang.com</span>

 

결과보기


방문 감사합니다. (즐겨찾기 등록: Ctrl + D)

분류 제목
DOM_Event JS - AltKey -
DOM_Event JS - altKey -
DOM_Event JS - animationName -
DOM_Event JS - bubbles 속성 - 이벤트확산여부판별 (= 확산이벤트판별 = 버블즈속성, IE9)
DOM_Event JS - button -
DOM_Event JS - buttons -
DOM_Event JS - cancelable -
DOM_Event JS - charCode -
DOM_Event JS - changeTouches -
DOM_Event JS - clientX 속성 - 현재창 기준 마우스커서 수평 좌표 위치 (= clientX속성 = 클라이언트…
DOM_Event JS - clientY -
DOM_Event JS - clipboardData 속성 - 클립보드에 넣을 데이터 지정 (= clipboardData속성 =…
DOM_Event JS - code -
DOM_Event JS - composed 속성 - 이벤트객체구성여부반환 (= 컴포우즈드속성)
DOM_Event JS - createEvent() 메서드 -
47/89
목록
  • 채팅방
  • 필독
1. 채팅창 헤드에서 접속자 확인 2. 닉네임 클릭해 1:1 채팅 가능 3. 닉네임 클릭해 귓속말 가능 4. 닉네임 클릭해 호출하기 가능 5. 우하단 클릭해 환경 설정 가능 6. 의뢰글 작성 후 의뢰 상담 가능 7. 질문글 작성 후 질문 상담 가능 8. 채팅방에 개인정보 입력 금지 9. 채팅방에 광고 욕설 비방 금지
 홈  PC버전 로그인 일본어
웹디자인언어
서버관리언어
고급코딩언어
그누보드
제작의뢰 1
Q&A
커뮤니티
웹유틸
회원센터
홈짱 PC버전 로그인