티스토리 뷰

노마드코더/Vanilla JS

#2-2 JS DOM Functions

준승박 2021. 8. 28. 12:33

DOM Functions?

문서 객체 모델(The Document Object Model, DOM) 은 HTML, XML 문서의 프로그래밍 interface이다.

 

JavaScript는 HTML에 있는 모든 요소를 가지고 와서 객체로 만든다. 따라서 모든 HTML은 객체가 되는 것이다. 객체는 많은 키를 가지고 있다. 우리가 찾게 될 모든 객체들의 함수를 DOM(Document Object Module) 형태로 변경할 수 있다. 예를 들어보자.

 

[index.html]

<!DOCTYPE html>
<html>
  <head>
    <title>Sample</title>
    <link rel="stylesheet" href="index.css" />
  </head>
  <body>
      <h1 id="title">This works!</h1>
      <script src="index.js"></script>
  </body>
</html>

[index.js]

const title = document.getElementById("title"); 
title.innerHTML = "Hi from js"; // title의 내용이 바뀐다. 
title.style.color = "red";
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함