• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 JavaScript, TS 게시판 for 반복문 2 하는중에 버튼 눌린게 안사라지는 현상 질문

for 반복문 2 하는중에 버튼 눌린게 안사라지는 현상 질문

  • 이 주제에는 1개 답변, 2명 참여가 있으며 codingapple3 년 전에 전에 마지막으로 업데이트했습니다.
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 글쓴이
  • #35519

    YDC
    참가자

    document.querySelectorAll('.tab-button')[0].addEventListener('click',function(){
      document.querySelector('.tab-button').classList.remove('orange')
      document.querySelectorAll('.tab-button')[0].classList.add('orange')
      document.querySelector('.tab-content').classList.remove('show')
      document.querySelectorAll('.tab-content')[0].classList.add('show')
    })
    document.querySelectorAll('.tab-button')[1].addEventListener('click',function(){
      document.querySelector('.tab-button').classList.remove('orange')
      document.querySelectorAll('.tab-button')[1].classList.add('orange')
      document.querySelector('.tab-content').classList.remove('show')
      document.querySelectorAll('.tab-content')[1].classList.add('show')
    })
    document.querySelectorAll('.tab-button')[2].addEventListener('click',function(){
      document.querySelector('.tab-button').classList.remove('orange')
      document.querySelectorAll('.tab-button')[2].classList.add('orange')
      document.querySelector('.tab-content').classList.remove('show')
      document.querySelectorAll('.tab-content')[2].classList.add('show')
    })

     

     

     

    $('.tab-button').eq(0).on('click',function () {
      $('.tab-button').removeClass('orange')
      $('.tab-button').eq(0).addClass('orange')
      $('.tab-content').removeClass('show')
      $('.tab-content').eq(0).addClass('show')
    })
    $('.tab-button').eq(1).on('click',function () {
      $('.tab-button').removeClass('orange')
      $('.tab-button').eq(1).addClass('orange')
      $('.tab-content').removeClass('show')
      $('.tab-content').eq(1).addClass('show')
    })
    $('.tab-button').eq(2).on('click',function () {
      $('.tab-button').removeClass('orange')
      $('.tab-button').eq(2).addClass('orange')
      $('.tab-content').removeClass('show')
      $('.tab-content').eq(2).addClass('show')
    })

    제이쿼리로 하면 잘 되는데

    자바스크립트로 짜놓으니깐 안되네요

    이유를 알고싶습니다.

    #35531

    codingapple
    키 마스터

    document.querySelector('.tab-button') 이러면 맨 처음 버튼만 찾아줍니다

2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠