JavaScript

[DOM_Event] JS - stopPropagation() 메서드 ★ - 이벤트확산방지 (= 이벤트전파방지 = stopPropagation메서드 = 스톱프로퍼게이션 메서드 = 스탑프라퍼게이션 메서드))

목차
  1. stopPropagation() 예제 - 이벤트 확산 방지
  2. stopPropagation() 정의

 

stopPropagation() 예제 - 이벤트 확산 방지

 

<style>

div {

  padding: 50px;

  background-color: rgba(255, 0, 0, 0.2);

  text-align: center;

  cursor: pointer;

}

</style>


<div onclick="homzzang2()">Hz 2

  <div onclick="homzzang1(event)">Hz 1</div>

</div>


확산방지: <input type="checkbox" id="check">


<script>

function homzzang1(event) {

  alert("Hz 1");

  if (document.getElementById("check").checked) {

    event.stopPropagation();

  }

}


function homzzang2() {

  alert("Hz 2");

}

</script>

 

결과보기

※ hz1을 그냥 클릭했을 때와 확산방지 체크를 하고 클릭했을 때 효과 비교.

 

stopPropagation() 정의

 

부모 요소나 자식 요소로 이벤트가 전파(= 확산)되는 것을 방지.



분류 제목
DOM_Event JS - stopImmediatePropagation() 메서드 -
DOM_Event JS - stopPropagation() 메서드 ★ - 이벤트확산방지 (= 이벤트전파방지 = stopProp…
DOM_Event JS - storageArea -
DOM_Event JS - target 속성 ★ -
DOM_Event JS - targetTouches -
DOM_Event JS - timeStamp -
DOM_Event JS - total -
DOM_Event JS - touches -
DOM_Event JS - transitionend -
DOM_Event JS - type -
DOM_Event JS - url -
DOM_Event JS - which -
DOM_Event JS - which -
DOM_Event JS - view 속성 - 이벤트 발생한 Window 객체 반환 (= view속성 = 뷰속성)
DOM_Event JS - initMouseEvent() 메서드 - 폐기예고. 마우스이벤트초기화
11/12
목록
 홈  PC버전 로그인 일본어
그누앞단언어
그누뒷단언어
그외코딩언어
그누보드
제작의뢰
Q&A
커뮤니티 2
웹유틸
회원센터
홈짱닷컴 PC버전 로그인