codestates / codestates/withpuppy

[❗️Error] 12/10 (김희원) getElementsByClassName()으로 인한 addEventListener is not a function 에러

Open
#85 0 comments 0 reactions 1 assignee Claimed by @heewonkim-dev View on GitHub
Error
Dominant language
JavaScript
Stars
0
Forks
3
PR merge metrics
No merged PRs in 30d

Description

### 마주친 에러에 대한 설명
- 내가 DOM으로 건드린 내용물에 이벤트를 추가하려고하니까 아래와 같은 오류 문구가 떴다.

### 에러 메세지 상세 내용

```js
Uncaught Type Error: .addEventListener is not a function.
```

### 해결하기 위한 노력과 방안
`getElementsByClassName()`으로 가져온 요소는 배열이라고한다. (getElements, 1개만이 아니라 여러개 다 가져온다는거다..)
`getElementsByClassName()`의 경우, 배열이다보니 반복문을 사용하거나 인덱스 번호를 명시해서 하나만 콕 찝어 사용해야한다고 한다.

### 레퍼런스
* [getElementsByClassName()으로 인한 addEventListener is not a function 에러](https://developer0809.tistory.com/153)
* [레딧에 올라온 에러](https://www.reddit.com/r/learnjavascript/comments/esl0mj/error_addeventlistener_is_not_a_function/)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.