const bttn = document.getElementById('bttn');//id속성있을때 사용한다
const nav = document.getElementById('nav');

bttn.addEventListener('click', () => { 
    nav.classList.toggle('active');//toggle()토글이란  on/off의 개념으로 스위치를 켰다,껏다하는기능이 있다
    bttn.classList.toggle('active');
});

https://developer.mozilla.org/ko/docs/Web/API/Document/getElementById

 

Document.getElementById() - Web API | MDN

Document.getElementById() 메서드는 주어진 문자열과 일치하는 id 속성을 가진 요소를 찾고, 이를 나타내는 Element 객체를 반환합니다. ID는 문서 내에서 유일해야 하기 때문에 특정 요소를 빠르게 찾을

developer.mozilla.org

 

'개발 공부 > js' 카테고리의 다른 글

Uncaught TypeError:$ajax is not a function error  (0) 2023.02.21
js 비교 연산자  (0) 2023.02.07
javasrcipt 예약어 특징  (0) 2023.02.07