댓글 검색 목록

[javascript] 단락의 배경색을 설정하는 JavaScript 프로그램 작성

페이지 정보

작성자 운영자 작성일 17-12-30 20:59 조회 1,197 댓글 0

HTML : 

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>단락의 배경색을 설정하는 JavaScript 프로그램 작성</title>
</head>
<body>
<input type="button" value="Click to set paragraph background color" onclick="set_background()">
<p>365ok.co.kr JavaScript Exercises</p>
<p>365ok.co.kr PHP Exercises</p> 
</body>
</html>



JS :

function set_background() {
 docBody = document.getElementsByTagName("body")[0];
  //Get all the p elements that are descendants of the body
  myBodyElements = docBody.getElementsByTagName("p");
// get the first p elements
  myp1 = myBodyElements[0];
  myp1.style.background = "rgb(255,0,0)";
// get the second p elements
  myp2 = myBodyElements[1];
  myp2.style.background = "rgb(255,255,0)";
}



댓글목록 0

등록된 댓글이 없습니다.

웹학교 로고

온라인 코딩학교

코리아뉴스 2001 - , All right reserved.