Day-19 querySelectorAll()

So Eun Ahn·2021년 1월 25일
0

JavaScript

목록 보기
22/26

querySelectorAll()

when using querySelector, which matches multiple elements only the first one will be selected. In order to select all the elements need to use querySelectorAll

'use strict';


const btnsOpenModal = document.querySelectorAll('.show-modal'); 

for (let i = 0; i < btnsOpenModal.length; i++) {
  btnsOpenModal[i].addEventListener('click', function () {
    console.log('button clicked');
  });
}

//btnsOpenModal[i] 이부분 이해 안되니까 집에 와서 다시 확인할것

mistake

const btnsOpenModal= document.querySelectorAll('.show-modal');

이 구문에서

const btnsOpenModal= document.querySelectorAll('show-modal');

class를 잡을때 . identifier를 안 붙혀서 value가 안잡혀서 왜 console에 log가 안되는지 고민함.

profile
오늘도 새로운 도전을 한다

0개의 댓글