HTML속성

모찌모찌·2024년 1월 18일

자바스크립트 공부

목록 보기
23/27

// HTML 속성 (HTML attribute)
const tomorrow = document.querySelector('#tomorrow');
const item = tomorrow.firstElementChild;
const link = item.firstElementChild;

elem.getAttribute('속성'): 속성에 접근하기

console.log(tomorrow.getAttribute('href'));
console.log(item.getAttribute('class'));

elem.setAttribute('속성', '값'): 속성 추가(수정)하기

tomorrow.setAttribute('class', 'list'); // 추가
link.setAttribute('href', 'https://www.codeit.kr'); // 수정

elem.removeAttribute('속성'): 속성 제거하기

tomorrow.removeAttribute('href');
tomorrow.removeAttribute('class');

profile
꼬꼬마 개발자 지망생

0개의 댓글