230216 항해99 102일차 e.preventDefault() vs e.stopPropagation()

요니링 컴터 공부즁·2023년 2월 27일
0

e.preventDefault()

  • html에서 a태그나 submit태그는 고유의 동작이 있다. 페이지를 이동시킨다거나 form 안에 있는 input 등을 전송한다던가 그러한 동작이 있는데 e.preventDefault는 그 동작을 중단시킨다.

e.stopPropagation()

  • e.stopPropagation는 이벤트가 상위 엘리먼트에 전달되지 않게 막아준다.

정리

  • e.preventDefault는 고유 동작을 중단시키고, e.stopPropagation는 상위 엘리먼트들로의 이벤트 전파를 중단시킨다.

출처: [개념잡기] e.preventDefault() 와 stopPropagation() 의 차이

0개의 댓글