● 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

댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입

사이트 정보

공지사항
자유게시판
질문답변
1:1문의

 

별명 : 터푸가위
주소 : 부산시 동래구 명장로20번길 90
대표 : 박규태
메일 : dancepkt@******.com

접속자집계

오늘
129
어제
285
최대
10,760
전체
277,735
Copyright © dancePKT . All rights reserved.