• 카테고리

    질문 & 답변
  • 세부 분야

    웹 개발

  • 해결 여부

    미해결

질문이 있습니다!

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

}

}

답변 1

답변을 작성해보세요.

0

아래처럼 해보세요^^

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);
	}
}
AirDream님의 프로필

AirDream

질문자

2021.02.27

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