불

html 엘리멘탈 이벤트 문의.

· 2012-09-14 (금) 14:53:36 · 2844 · 3
<div>
<div></div>
</div>

div안에 있는 div가 제거될시 이벤트가 발생되게 하고 싶은데..

이런 이벤트가 있나요?


|

댓글 3개

오브젝트가 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>
정말로 고맙습니다.
jQuery에 대해서 어느 정도 안다고 생각하고 있었는데 이런 것도 있군요.
좋은 정보 감사합니다.
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,188건
+
제목 글쓴이 날짜 조회
12-10-08 조회 4,517
12-10-08 조회 4,329
12-10-08 조회 8,866
12-10-08 조회 4,402
12-10-08 조회 4,095
12-10-07 조회 3,902
12-10-05 조회 5,615
12-10-05 조회 5,582
12-10-05 조회 3,783
12-10-05 조회 4,146
12-10-05 조회 7,410
12-10-04 조회 3,402
12-10-04 조회 3,819
12-10-03 조회 4,504
12-10-03 조회 4,650
12-10-03 조회 4,646
12-10-03 조회 4,345
12-10-03 조회 7,463
12-10-02 조회 3,716
12-10-02 조회 8,993
12-10-02 조회 4,321
12-10-01 조회 4,422
12-09-30 조회 4,156
12-09-29 조회 3,717
12-09-29 조회 4,425
12-09-28 조회 3,391
12-09-28 조회 5,008
12-09-28 조회 3,272
12-09-28 조회 3,186
12-09-27 조회 5,954
12-09-27 조회 3,748
12-09-27 조회 3,369
12-09-27 조회 3,110
12-09-27 조회 3,736
12-09-26 조회 4,928
12-09-26 조회 3,244
12-09-25 조회 4,406
12-09-25 조회 3,332
12-09-25 조회 3,306
12-09-25 조회 5,399
12-09-24 조회 3,636
12-09-24 조회 3,792
12-09-24 조회 3,205
12-09-24 조회 4,200
12-09-24 조회 3,210
12-09-24 조회 3,481
12-09-23 조회 3,082
12-09-23 조회 3,129
12-09-23 조회 3,146
12-09-23 조회 3,254
12-09-22 조회 4,431
12-09-21 조회 3,330
12-09-21 조회 3,474
12-09-21 조회 4,448
12-09-21 조회 3,559
12-09-20 조회 5,270
12-09-20 조회 3,010
12-09-20 조회 5,993
12-09-19 조회 3,218
12-09-18 조회 6,002
12-09-18 조회 3,476
12-09-18 조회 3,593
12-09-18 조회 3,819
12-09-18 조회 2,791
12-09-18 조회 2,894
12-09-18 조회 3,960
12-09-18 조회 4,617
12-09-18 조회 3,176
12-09-18 조회 2,853
12-09-18 조회 2,991
12-09-18 조회 3,152
12-09-18 조회 4,069
12-09-17 조회 3,456
12-09-17 조회 2,950
12-09-17 조회 2,855
12-09-17 조회 2,958
12-09-17 조회 3,201
12-09-17 조회 3,128
12-09-16 조회 2,944
12-09-16 조회 3,904
12-09-16 조회 3,047
12-09-15 조회 8,361
12-09-15 조회 3,537
12-09-14 조회 3,022
12-09-14 조회 4,310
12-09-14 조회 2,845
12-09-14 조회 3,830
12-09-14 조회 5,399
12-09-14 조회 2,865
12-09-14 조회 2,899
12-09-13 조회 2,958
12-09-13 조회 2,877
12-09-13 조회 2,746
12-09-13 조회 3,020
12-09-13 조회 2,818
12-09-13 조회 3,332
12-09-13 조회 3,470
12-09-13 조회 3,015
12-09-12 조회 2,823
12-09-12 조회 3,004