4 글 보임 - 1 에서 4 까지 (총 4 중에서)
-
글쓴이글
-
2024년 1월 15일 15:41 #110234
전태수참가자jQuery 방식 말고, 바닐라 스크립트로 구현하고 싶어서 이렇게 해봤는데, classList.remove 가 먹히질 않고 있는데, 어떤 문제가 있을까요?
for(let i = 0; i < 3; i++){ document.querySelectorAll('.tab-button')[i].addEventListener('click', function(){ document.querySelectorAll('.tab-button')[i].classList.remove('orange'); document.querySelectorAll('.tab-button')[i].classList.add('orange'); document.querySelectorAll('.tab-content')[i].classList.remove('show'); document.querySelectorAll('.tab-content')[i].classList.add('show');
console.log(i) }); }
2024년 1월 15일 19:16 #110267
codingapple키 마스터document.querySelectorAll('.tab-button')[0].classList.remove('orange'); document.querySelectorAll('.tab-button')[1].classList.remove('orange'); document.querySelectorAll('.tab-button')[2].classList.remove('orange'); 라고 쓰면 orange 다 없어질듯요
2024년 1월 16일 11:23 #110326
전태수참가자for(let i = 0; i < 3; i++){ document.querySelectorAll('.tab-button')[i].addEventListener('click', function(){ // document.querySelectorAll('.tab-button')[i].classList.remove('orange'); document.querySelectorAll('.tab-button')[0].classList.remove('orange'); document.querySelectorAll('.tab-button')[1].classList.remove('orange'); document.querySelectorAll('.tab-button')[2].classList.remove('orange');
document.querySelectorAll('.tab-button')[i].classList.add('orange'); // document.querySelectorAll('.tab-content')[i].classList.remove('show'); document.querySelectorAll('.tab-content')[0].classList.remove('show'); document.querySelectorAll('.tab-content')[1].classList.remove('show'); document.querySelectorAll('.tab-content')[2].classList.remove('show'); document.querySelectorAll('.tab-content')[i].classList.add('show');
console.log(i) }); } 알려주신대로 이렇게 하니까 잘 되긴 하는데, document.querySelectorAll('.tab-button')[i].classList.remove('orange'); 이 방법으로는 전체 reomve가 힘들까요?
-
글쓴이글
4 글 보임 - 1 에서 4 까지 (총 4 중에서)
- 답변은 로그인 후 가능합니다.