● 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 트리의 루트이기 때문이다.
- 이전글▶ document.getElementById().value 21.07.18
- 다음글document.getElementById() - 버튼 클릭시 style 적용 21.07.18
댓글목록
등록된 댓글이 없습니다.