● document.getElementById() - style 적용 > SCRIPT

본문 바로가기

사이트 내 전체검색

뒤로가기 SCRIPT

● document.getElementById() - style 적용

본문

<h3>document 객체의 getElementById() 메소드 호출</h3>


<p id="firstP">안녕하세요</p>

<p id="secondP">안녕하세요</p>

<p id="thirdP">안녕하세요</p>


<script>

var p = document.getElementById("firstP");

p.style.color = "red";


document.getElementById("secondP").style.color = "blue";

document.getElementById("firstP").style.backgroundColor = "green";

document.getElementById("secondP").style.backgroundColor = "#007f00";

document.getElementById("thirdP").style.backgroundColor = "rgb(0,127,0)";

</script>



==== tip ====

getElementById() 메소드는 왜 document의 멤버일까?

HTML 문서 전체를 대표하는 객체가 document이고 DOM 트리의 루트이기 때문이다.

추천0 비추천 0

댓글목록 0

등록된 댓글이 없습니다.


Copyright © dancePKT. All rights reserved.
PC 버전으로 보기