인프런 커뮤니티 질문&답변
질문이 있습니다!
작성
·
232
0
이전에 이벤트 위임 보강 영상에서 사용했던 코드로 써도 되나요?
function doorHandler(e) {
const targetElem = e.target;
targetElem.parentNode.classList.add('door-opened');
if (targetElem.nodeName='BODY') {
targeElem = null;
return
}
}
답변 1
0
1분코딩
지식공유자
아래처럼 해보세요^^
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);
}
}





if 대신에 함수로 기능별로 나눠줘서 써줘도 되나용?