<div>
<div></div>
</div>
div안에 있는 div가 제거될시 이벤트가 발생되게 하고 싶은데..
이런 이벤트가 있나요?
댓글 3개
letsgolee
13년 전
오브젝트가 destroy될 때 이벤트 발생관련하는게 원래 자바스크립트에는 없습니다. 다만 setTimeout을 이용해서 만들 수는 있습니다. 다행히 jQuery에 destroyed라는 event를 추가해주는 플러그인을 만든 사람이 있네요. 이걸 이용하면 쉽게 짤 수 있습니다. 예제소스를 만들어보았으니 테스트해보면 쉽게 알수 있어요. 원리도 간단합니다. 단순하게 bind로 destroyed event 추가만 해주면 되요.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> Test for jQuery event.destroyed </title>
<meta http-equiv='content-type' content='text/html; charset=utf-8' />
<meta name="Generator" content="EditPlus" />
<meta name="Author" content="Jacob Lee" />
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<!--<script src="jquery.event.destroyed.js"
type="text/javascript"></script>-->
<script src="http://v3.javascriptmvc.com/jquery/dist/jquery.event.destroyed.js"
type="text/javascript"></script>
</head>
<body>
<!-- Test for jQuery event.destroyed
When a object is destroyed, the event will show -->
<div class="container">
<div class="hello">Hello</div>
<div class="goodbye">Goodbye</div>
</div>
<button onclick="destroy_hello();">Click Me!</button>
<script type="text/javascript">
$(document).ready(function(){
$('.hello').bind('destroyed', function(){alert('goodbye "Hello"!');});
});
function destroy_hello()
{
$('.hello').remove();
}
</script>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> Test for jQuery event.destroyed </title>
<meta http-equiv='content-type' content='text/html; charset=utf-8' />
<meta name="Generator" content="EditPlus" />
<meta name="Author" content="Jacob Lee" />
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<!--<script src="jquery.event.destroyed.js"
type="text/javascript"></script>-->
<script src="http://v3.javascriptmvc.com/jquery/dist/jquery.event.destroyed.js"
type="text/javascript"></script>
</head>
<body>
<!-- Test for jQuery event.destroyed
When a object is destroyed, the event will show -->
<div class="container">
<div class="hello">Hello</div>
<div class="goodbye">Goodbye</div>
</div>
<button onclick="destroy_hello();">Click Me!</button>
<script type="text/javascript">
$(document).ready(function(){
$('.hello').bind('destroyed', function(){alert('goodbye "Hello"!');});
});
function destroy_hello()
{
$('.hello').remove();
}
</script>
</body>
</html>
13년 전
정말로 고맙습니다.
SMaker
13년 전
jQuery에 대해서 어느 정도 안다고 생각하고 있었는데 이런 것도 있군요.
좋은 정보 감사합니다.
좋은 정보 감사합니다.
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6130 |
gender
|
12년 전 | 1090 | |
| 6129 | 12년 전 | 1321 | ||
| 6128 |
|
12년 전 | 3461 | |
| 6127 | 12년 전 | 695 | ||
| 6126 |
|
12년 전 | 2206 | |
| 6125 |
|
12년 전 | 4884 | |
| 6124 | 12년 전 | 660 | ||
| 6123 | 12년 전 | 3838 | ||
| 6122 | 12년 전 | 1016 | ||
| 6121 | 12년 전 | 3750 | ||
| 6120 | 12년 전 | 907 | ||
| 6119 | 12년 전 | 1769 | ||
| 6118 | 12년 전 | 928 | ||
| 6117 | 12년 전 | 2147 | ||
| 6116 | 12년 전 | 7942 | ||
| 6115 | 12년 전 | 1918 | ||
| 6114 |
|
12년 전 | 1705 | |
| 6113 | 12년 전 | 1522 | ||
| 6112 | 12년 전 | 593 | ||
| 6111 | 12년 전 | 2109 | ||
| 6110 | 12년 전 | 1849 | ||
| 6109 | 12년 전 | 638 | ||
| 6108 | 12년 전 | 1197 | ||
| 6107 | 12년 전 | 619 | ||
| 6106 | 12년 전 | 904 | ||
| 6105 | 12년 전 | 1189 | ||
| 6104 | 12년 전 | 3594 | ||
| 6103 | 12년 전 | 2120 | ||
| 6102 | 12년 전 | 2311 | ||
| 6101 | 12년 전 | 3674 | ||
| 6100 | 12년 전 | 3481 | ||
| 6099 | 12년 전 | 3149 | ||
| 6098 | 12년 전 | 4022 | ||
| 6097 | 12년 전 | 1012 | ||
| 6096 | 12년 전 | 5978 | ||
| 6095 | 12년 전 | 1369 | ||
| 6094 | 12년 전 | 1223 | ||
| 6093 | 12년 전 | 3405 | ||
| 6092 | 12년 전 | 3051 | ||
| 6091 | 12년 전 | 5192 | ||
| 6090 | 12년 전 | 2701 | ||
| 6089 | 12년 전 | 3326 | ||
| 6088 | 12년 전 | 1014 | ||
| 6087 | 12년 전 | 846 | ||
| 6086 | 12년 전 | 2017 | ||
| 6085 |
|
12년 전 | 806 | |
| 6084 |
웹디자인되고파
|
12년 전 | 2216 | |
| 6083 | 12년 전 | 1506 | ||
| 6082 | 12년 전 | 1110 | ||
| 6081 | 12년 전 | 2097 | ||
| 6080 |
Stiven
|
12년 전 | 2312 | |
| 6079 |
프로프리랜서
|
12년 전 | 1317 | |
| 6078 |
프로프리랜서
|
12년 전 | 786 | |
| 6077 |
프로프리랜서
|
12년 전 | 1341 | |
| 6076 |
프로프리랜서
|
12년 전 | 829 | |
| 6075 |
프로프리랜서
|
12년 전 | 1219 | |
| 6074 | 12년 전 | 3854 | ||
| 6073 | 12년 전 | 3949 | ||
| 6072 | 12년 전 | 1373 | ||
| 6071 | 12년 전 | 6990 | ||
| 6070 | 12년 전 | 7574 | ||
| 6069 | 12년 전 | 2318 | ||
| 6068 | 12년 전 | 3866 | ||
| 6067 |
smwkd
|
12년 전 | 632 | |
| 6066 | 12년 전 | 3655 | ||
| 6065 | 12년 전 | 3486 | ||
| 6064 | 12년 전 | 2720 | ||
| 6063 | 12년 전 | 2840 | ||
| 6062 | 12년 전 | 2368 | ||
| 6061 | 12년 전 | 2276 | ||
| 6060 | 12년 전 | 5182 | ||
| 6059 | 12년 전 | 2811 | ||
| 6058 | 12년 전 | 3133 | ||
| 6057 | 12년 전 | 2261 | ||
| 6056 | 12년 전 | 6839 | ||
| 6055 | 12년 전 | 2581 | ||
| 6054 | 12년 전 | 3433 | ||
| 6053 | 12년 전 | 2323 | ||
| 6052 | 12년 전 | 4818 | ||
| 6051 | 12년 전 | 3710 | ||
| 6050 | 12년 전 | 2554 | ||
| 6049 | 12년 전 | 2243 | ||
| 6048 |
|
12년 전 | 1294 | |
| 6047 | 12년 전 | 3438 | ||
| 6046 | 12년 전 | 4094 | ||
| 6045 | 12년 전 | 3454 | ||
| 6044 | 12년 전 | 5331 | ||
| 6043 | 12년 전 | 1650 | ||
| 6042 | 12년 전 | 1281 | ||
| 6041 | 12년 전 | 5163 | ||
| 6040 | 12년 전 | 937 | ||
| 6039 | 12년 전 | 3408 | ||
| 6038 | 12년 전 | 3410 | ||
| 6037 | 12년 전 | 2992 | ||
| 6036 | 12년 전 | 3340 | ||
| 6035 | 12년 전 | 2867 | ||
| 6034 | 12년 전 | 2844 | ||
| 6033 | 12년 전 | 2866 | ||
| 6032 | 12년 전 | 2854 | ||
| 6031 | 12년 전 | 2878 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기