-
카테고리
-
세부 분야
웹 개발
-
해결 여부
미해결
질문이 있습니다!
21.02.18 21:18 작성 조회수 153
0
이전에 이벤트 위임 보강 영상에서 사용했던 코드로 써도 되나요?
function doorHandler(e) {
const targetElem = e.target;
targetElem.parentNode.classList.add('door-opened');
if (targetElem.nodeName='BODY') {
targeElem = null;
return
}
}
답변을 작성해보세요.
0
1분코딩
지식공유자2021.02.25
아래처럼 해보세요^^
function doorHandler(e) {
let targetElem = e.target;
while (!targetElem.classList.contains('door-body')) {
targetElem = targetElem.parentNode;
if (targetElem.nodeName == 'BODY') {
targetElem = null;
if (currentItem) inactivate(currentItem);
return;
}
}
if (currentItem) inactivate(currentItem);
if (targetElem.classList.contains('door-body')) {
activate(targetElem.parentNode);
}
}
답변 1