Notice
Recent Posts
Recent Comments
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- animation
- scroll
- 이벤트
- 모듈
- 문자열
- dom
- Flex
- 스크롤
- event
- input
- Promise
- 애니메이션
- ES6
- video
- 배열
- This
- ios
- 비동기
- 객체
- array
- Push
- map
- 클로저
- 이벤트 위임
- slice
- 이벤트 루프
- ajax
- json
- object
- IntersectionObserver
Archives
- Today
- Total
FEDev Story
커스텀 이벤트 디스패치 본문
https://ko.javascript.info/dispatch-events
const allView = document.querySelector('.selectbox');
const category = document.querySelector('.category');
const dimDiv = document.querySelector('.dimmed');
const customEvent = document.createEvent('Event');
customEvent.initEvent('click', false, true);
allView && allView.addEventListener('click', (e) => {
category.classList.toggle('active');
dimDiv.classList.toggle('active');
});
dimDiv && dimDiv.addEventListener('click', (e) => {
if(dimDiv.classList.contains('dimmed')){
allView.dispatchEvent(customEvent);
}
});
커스텀 이벤트 디스패치
ko.javascript.info
'Javascript' 카테고리의 다른 글
| [드림코딩][ES6] 자바스크립트 7. 오브젝트 넌 뭐니? | 프론트엔드 개발자 입문편 (0) | 2021.09.10 |
|---|---|
| javascript get child index (0) | 2021.09.03 |
| 요소의 절대좌표 상대좌표 구하기 (0) | 2021.08.19 |
| 자바스크립트 insertAfter() 구현하기 (0) | 2021.08.18 |
| 자바스크립트 제대로 공부하는 방법 (0) | 2016.08.25 |
Comments