달력

3

« 2024/3 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

'Javascript & HTML & CSS/jQuery'에 해당되는 글 6

  1. 2016.12.06 jquery 이벤트 막기
2016. 12. 6. 23:16

jquery 이벤트 막기 Javascript & HTML & CSS/jQuery2016. 12. 6. 23:16

기본 이벤트를 제거하는 함수

preventDefault();


사용법

$("div").on('click', function(e){

e.preventDefault();

});




이벤트 전달을 막기

stopPropagation();


사용법

$("div").on('click', function(e){

e.stopPropagation();

}





<html>

<head>

<script src="https://code.jquery.com/jquery-3.1.1.js"></script>

<style>

div{

width:100px;

height:100px;

background-color:red;

}

</style>

<script>

$(function(){

$("div>a").on('click', function(e){

e.stopPropagation();

e.preventDefault();

});

$("div").on('click', function(){

alert();

});

});

</script>

</head>

<body>

<div>

<a href="http://www.naver.com">naver</a>

</div>

</body>

</html>

'Javascript & HTML & CSS > jQuery' 카테고리의 다른 글

jQuery pivot plugin  (0) 2017.01.05
이벤트 발생시 this  (0) 2016.12.07
jquery 이벤트전달 막기 + 기본이벤트 제거 방법  (0) 2016.12.06
dialog, datepicker 플러그인  (0) 2016.12.04
jquery 최신 cdn  (0) 2016.08.11
:
Posted by 클레잇