[DEV] DOM API 2카테고리 없음2021. 6. 28. 08:26
Table of Contents
- DOM API (Document Object Model, Application Programming Interface)
// HTML 요소(Element) 모두 검색/찾기
const boxEls = document.querySelectorAll('.box');
console.log(boxEls);
// 찾은 요소를 반복해서 함수 실행
// 익명 함수를 인수로 추가
boxEls.forEach(function () {});
//첫 번째 매개변수 (boxEl) : 반복 중인 요소
//두 번째 매개변수 (index) : 반복 중인 번호
boxEl.forEach(function (boxEl, index) {});
// 출력
boxEls.forEach(function (boxEl, index) {
boxEl.classList.add('order-${index + 1}');
console.log(index, boxEl);
});
const boxEl = document.querySelector('.box');
// Getter, 값을 얻는 용도
console.log(boxEl.textContent); // Box
// Setter, 값을 지정하는 용도
boxEl.textContent = 'abc';
console.log(boxEl.textContent); //abc
@Potato_H :: 코딩하는 감자
기억보단 기록을
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!