JavaScript

[CSS_Objects] JS - style.cssText 속성 - 인라인스타일선언내용 설정/반환

목차
  1. cssText 예제 - 스타일 반환
  2. cssText 정의
  3. cssText 구문
  4. cssText 예제 - 스타일 설정

 

cssText 예제 - 스타일 반환 

 

<h1 style="color: red; font-size:30px;">홈짱닷컴 Homzzang.com</h1>


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


<p id="demo"></p>


<script>

function homzzang() {

  var h1 = document.getElementsByTagName("h1")[0];

  var x = h1.style.cssText;

  document.getElementById("demo").innerHTML = x;

}

</script>

 

결과보기 (결과값: color: red; font-size: 30px;)

주의: 내부스타일이나 외부스타일 경우엔 작동 X

 

cssText 정의

 

요소의 인라인스타일 선언값 설정/반환.

 


 

1.

모든 브라우저 지원.

 

2.

DOM 버전 : Level 2 Style CSS

 

3. MDN cssText 예제 보기

https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleDeclaration/cssText

 

 

cssText 구문

 

[반환] - 인라인스타일 문자열 반환.

element.style.cssText 

 

[설정]

element.style.cssText = inlineStyleCode


 

cssText 예제 - 스타일 설정

 

<h1 style="color:red; font-size: 50px">Homzzang.com</h1>


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


<script>

function homzzang() {

  var h1 = document.getElementsByTagName("h1")[0];

  h1.style.cssText = "color: blue;";

}

</script> 

 

결과보기 



분류 제목
DOM_Style JS - borderRadius 속성 ★ - 테두리 둥글게 설정/반환 = 둥근 테두리 = 보더레이디어스 속성…
DOM_Style JS - borderRight -
DOM_Style JS - borderRightColor -
DOM_Style JS - borderRightStyle -
DOM_Style JS - borderRightWidth -
DOM_Style JS - borderSpacing 속성 - 테이블의 셀 간 간격 설정/반환 (= borderSpacing속성…
DOM_Style JS - borderStyle 속성 - 테두리스타일
DOM_Style JS - borderTop 속성 - 테두리상단 (= 상단테두리)
DOM_Style JS - borderTopColor -
DOM_Style JS - borderTopLeftRadius -
DOM_Style JS - borderTopRightRadius -
DOM_Style JS - borderTopStyle -
DOM_Style JS - borderTopWidth -
DOM_Style JS - borderWidth 속성 - 테두리두께 (= 보더위드스속성 = border-width속성) ★
DOM_Style JS - bottom 속성 - 기준하단 (= bottom속성 = 하단기준 = 아래기준 = 바텀속성 = 보텀속…
59/89
목록
 홈  PC버전 로그인 일본어
그누앞단언어
그누뒷단언어
그외코딩언어
그누보드
제작의뢰
Q&A
커뮤니티
웹유틸
회원센터
홈짱닷컴 PC버전 로그인