🔖 HTML 문서(document)의 구성 요소(Object)를 알아내고 사용할 수 있다. 태그를 객체(Object)로 저장해 두는 것이 DOM의 개념!
🔖 JavaScript를 사용할 줄 안다면, DOM을 통해 HTML 조작 -> 문서 구조, 스타일, 내용 등의 변경이 가넝해짐!
🔖 웹 페이지의 객체 지향 표현
문서 객체(document) : HTML문서의 구성 요소를 의미
- 기본적으로 document.createElement('') 메소드로 태그 생성이 가능하다.
- document.body.append()를 통해 특정 태그 안으로 ()의 태그를 넣기도 가능하다.
document.getElementById('아이디') : 변수document.getElementsByClassName('클래스') : 배열document.getElementsByTagName('태그') : 배열document.querySelector('선택자') : 변수document.querySelectorAll('선택자') : 배열getAttribute('속성이름') : 속성 값 알아내기setAttribute('속성', '값') : 속성 값 변경하기DOM 관점에서의 속성
property (prop 관점에서는 클래스이름이 className <-> attr 관점에서는 class)
<div class="primary" id="area">텍스트</div>
<script>
document.getElementById('area').className = 'boom';
// JS로 속성들을 저장시킨 후에는 더이상 attr(attribute)이 아닌 prop(property)이다.
document.getElementById('area').setAttribute('class', 'baam');
// class 이름 변경 가능 -> html의 관점(attribute)에서 class와 js관점(property)에서 className은 같다는 것을 확인 가능!
</script>
-> 속성 이름을 그대로 가져다 쓰는 경우네는 getAttribute를 쓰는 것이 안전합니다용