• 회원가입
  • 로그인
  • 구글아이디로 로그인

[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>

 

결과보기



분류 제목
CSS_Objects JS - setProperty() 메서드 - 새 CSS속성설정 / 기존CSS속성수정 (= setPropert…
DOM JS - NodeList 속성 - 노드리스트 (= 노드목록)
Basic JS - this 키워드 ★★★★★ - 호출 방식에 따라 지시 대상 다름. (= 디스 키워드)
Functions JS - apply() 메서드 - 함수호출방법3 (= 어플라이메서드)
Functions JS - Closure - 클로저 (전역변수/지역변수/카운터)
Math JS - Math.atanh() 메서드 - 쌍곡선 아크탄젠트 (IE12 이상)
Math JS - Math.acosh() 메서드 - 쌍곡선 아크코사인 (IE12 이상)
Math JS - Math.asinh() 메서드 - 쌍곡선 아크사인 반환 (= asinh 메서드)
Math JS - Math.cbrt() 메서드 - 세제곱근
Math JS - Math.tanh() 메서드 - 쌍곡선 탄젠트 (IE12 이상)
Math JS - Math.trunc() 메서드 - 숫자의 정수부분 추출 (= trunc메서드 = 트런크메서드) (I…
Math JS - Math.cosh() 메서드 - 쌍곡선 코사인
Math JS - Math.sinh() 메서드 - 쌍곡선 사인값 (IE12 이상)
DOM_Event JS - initMouseEvent() 메서드 - 폐기예고. 마우스이벤트초기화
js JS - getRangeAt() 메서드
DOM_Document JS - styleSheets 속성 - 스타일시트집합
js JS - rules 속성 - styleSheets 객체의 속성
DOM_Event JS - cancelBubble 속성 - 부모요소로 이벤트 확산 방지 (= 상위요소로 이벤트확산취소 = 캔슬…
DOM_Event JS - composedPath() 메서드 - 이벤트객체흐름파악 (=이벤트실행객체경로파악 = 컴포우즈드패스메…
js JS - 특정요소 함수실행제외 (= 배열문자열포함검사) ★★★★★
61/67
목록
찾아주셔서 감사합니다. Since 2012