<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에 대해서 어느 정도 안다고 생각하고 있었는데 이런 것도 있군요.
좋은 정보 감사합니다.
좋은 정보 감사합니다.
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6230 |
senseme
|
12년 전 | 1062 | |
| 6229 |
senseme
|
12년 전 | 1081 | |
| 6228 | 12년 전 | 4441 | ||
| 6227 |
senseme
|
12년 전 | 1497 | |
| 6226 |
senseme
|
12년 전 | 1645 | |
| 6225 | 12년 전 | 5501 | ||
| 6224 | 12년 전 | 3272 | ||
| 6223 |
kiplayer
|
12년 전 | 2142 | |
| 6222 | 12년 전 | 1304 | ||
| 6221 | 12년 전 | 3497 | ||
| 6220 | 12년 전 | 2520 | ||
| 6219 | 12년 전 | 2231 | ||
| 6218 |
senseme
|
12년 전 | 1845 | |
| 6217 |
senseme
|
12년 전 | 1539 | |
| 6216 |
senseme
|
12년 전 | 1530 | |
| 6215 |
senseme
|
12년 전 | 1286 | |
| 6214 | 12년 전 | 2399 | ||
| 6213 |
senseme
|
12년 전 | 1673 | |
| 6212 |
senseme
|
12년 전 | 1349 | |
| 6211 |
senseme
|
12년 전 | 2438 | |
| 6210 |
senseme
|
12년 전 | 1618 | |
| 6209 | 12년 전 | 2223 | ||
| 6208 | 12년 전 | 3446 | ||
| 6207 | 12년 전 | 1227 | ||
| 6206 |
senseme
|
12년 전 | 2198 | |
| 6205 | 12년 전 | 1042 | ||
| 6204 |
kiplayer
|
12년 전 | 1533 | |
| 6203 |
senseme
|
12년 전 | 2129 | |
| 6202 |
senseme
|
12년 전 | 1757 | |
| 6201 |
senseme
|
12년 전 | 4571 | |
| 6200 |
senseme
|
12년 전 | 2671 | |
| 6199 |
senseme
|
12년 전 | 2835 | |
| 6198 |
senseme
|
12년 전 | 1240 | |
| 6197 |
senseme
|
12년 전 | 8559 | |
| 6196 |
senseme
|
12년 전 | 3347 | |
| 6195 | 12년 전 | 1438 | ||
| 6194 |
|
12년 전 | 1294 | |
| 6193 |
senseme
|
12년 전 | 2698 | |
| 6192 |
senseme
|
12년 전 | 5370 | |
| 6191 |
senseme
|
12년 전 | 3418 | |
| 6190 | 12년 전 | 1348 | ||
| 6189 | 12년 전 | 13504 | ||
| 6188 |
웹디자인되고파
|
12년 전 | 1209 | |
| 6187 | 12년 전 | 627 | ||
| 6186 | 12년 전 | 3938 | ||
| 6185 | 12년 전 | 1477 | ||
| 6184 | 12년 전 | 9385 | ||
| 6183 | 12년 전 | 796 | ||
| 6182 |
senseme
|
12년 전 | 1242 | |
| 6181 |
senseme
|
12년 전 | 3227 | |
| 6180 |
senseme
|
12년 전 | 856 | |
| 6179 |
senseme
|
12년 전 | 1769 | |
| 6178 | 12년 전 | 3634 | ||
| 6177 | 12년 전 | 1067 | ||
| 6176 | 12년 전 | 959 | ||
| 6175 |
senseme
|
12년 전 | 5305 | |
| 6174 |
senseme
|
12년 전 | 1434 | |
| 6173 |
senseme
|
12년 전 | 755 | |
| 6172 |
senseme
|
12년 전 | 2746 | |
| 6171 |
senseme
|
12년 전 | 2490 | |
| 6170 |
senseme
|
12년 전 | 1507 | |
| 6169 |
senseme
|
12년 전 | 2933 | |
| 6168 |
senseme
|
12년 전 | 6536 | |
| 6167 | 12년 전 | 2141 | ||
| 6166 | 12년 전 | 747 | ||
| 6165 |
페이지팩트
|
12년 전 | 1911 | |
| 6164 |
네오soft
|
12년 전 | 1861 | |
| 6163 |
|
12년 전 | 2607 | |
| 6162 | 12년 전 | 592 | ||
| 6161 |
|
12년 전 | 1695 | |
| 6160 | 12년 전 | 777 | ||
| 6159 | 12년 전 | 1778 | ||
| 6158 |
|
12년 전 | 2685 | |
| 6157 |
sa2pan
|
12년 전 | 1249 | |
| 6156 | 12년 전 | 3894 | ||
| 6155 | 12년 전 | 9969 | ||
| 6154 | 12년 전 | 1126 | ||
| 6153 | 12년 전 | 2455 | ||
| 6152 |
생각보다몸이앞서다
|
12년 전 | 2128 | |
| 6151 | 12년 전 | 2978 | ||
| 6150 |
kiplayer
|
12년 전 | 6010 | |
| 6149 |
|
12년 전 | 2650 | |
| 6148 | 12년 전 | 2975 | ||
| 6147 |
hwang007
|
12년 전 | 953 | |
| 6146 |
aqqasdf
|
12년 전 | 773 | |
| 6145 | 12년 전 | 1865 | ||
| 6144 | 12년 전 | 5881 | ||
| 6143 |
smwkd
|
12년 전 | 1468 | |
| 6142 | 12년 전 | 4706 | ||
| 6141 | 12년 전 | 931 | ||
| 6140 | 12년 전 | 4102 | ||
| 6139 | 12년 전 | 1245 | ||
| 6138 | 12년 전 | 1097 | ||
| 6137 |
SugarSkull
|
12년 전 | 1684 | |
| 6136 | 12년 전 | 1314 | ||
| 6135 |
한번잘해보자
|
12년 전 | 563 | |
| 6134 |
프리랜서개발자
|
12년 전 | 544 | |
| 6133 |
basaria
|
12년 전 | 20448 | |
| 6132 | 12년 전 | 510 | ||
| 6131 | 12년 전 | 1087 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기