불

html 엘리멘탈 이벤트 문의.

· 2012-09-14 (금) 14:53:36 · 2841 · 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,508
12-10-08 조회 4,316
12-10-08 조회 8,864
12-10-08 조회 4,401
12-10-08 조회 4,091
12-10-07 조회 3,902
12-10-05 조회 5,613
12-10-05 조회 5,580
12-10-05 조회 3,783
12-10-05 조회 4,145
12-10-05 조회 7,407
12-10-04 조회 3,402
12-10-04 조회 3,819
12-10-03 조회 4,501
12-10-03 조회 4,649
12-10-03 조회 4,635
12-10-03 조회 4,342
12-10-03 조회 7,462
12-10-02 조회 3,716
12-10-02 조회 8,990
12-10-02 조회 4,321
12-10-01 조회 4,417
12-09-30 조회 4,154
12-09-29 조회 3,716
12-09-29 조회 4,424
12-09-28 조회 3,390
12-09-28 조회 5,008
12-09-28 조회 3,270
12-09-28 조회 3,185
12-09-27 조회 5,950
12-09-27 조회 3,743
12-09-27 조회 3,368
12-09-27 조회 3,110
12-09-27 조회 3,732
12-09-26 조회 4,924
12-09-26 조회 3,242
12-09-25 조회 4,396
12-09-25 조회 3,330
12-09-25 조회 3,306
12-09-25 조회 5,390
12-09-24 조회 3,636
12-09-24 조회 3,789
12-09-24 조회 3,205
12-09-24 조회 4,198
12-09-24 조회 3,210
12-09-24 조회 3,481
12-09-23 조회 3,081
12-09-23 조회 3,128
12-09-23 조회 3,145
12-09-23 조회 3,254
12-09-22 조회 4,430
12-09-21 조회 3,330
12-09-21 조회 3,474
12-09-21 조회 4,445
12-09-21 조회 3,555
12-09-20 조회 5,268
12-09-20 조회 3,009
12-09-20 조회 5,989
12-09-19 조회 3,217
12-09-18 조회 6,002
12-09-18 조회 3,476
12-09-18 조회 3,591
12-09-18 조회 3,819
12-09-18 조회 2,790
12-09-18 조회 2,892
12-09-18 조회 3,958
12-09-18 조회 4,617
12-09-18 조회 3,173
12-09-18 조회 2,853
12-09-18 조회 2,989
12-09-18 조회 3,151
12-09-18 조회 4,061
12-09-17 조회 3,455
12-09-17 조회 2,944
12-09-17 조회 2,855
12-09-17 조회 2,954
12-09-17 조회 3,200
12-09-17 조회 3,128
12-09-16 조회 2,943
12-09-16 조회 3,899
12-09-16 조회 3,047
12-09-15 조회 8,357
12-09-15 조회 3,537
12-09-14 조회 3,020
12-09-14 조회 4,308
12-09-14 조회 2,842
12-09-14 조회 3,830
12-09-14 조회 5,396
12-09-14 조회 2,865
12-09-14 조회 2,899
12-09-13 조회 2,957
12-09-13 조회 2,877
12-09-13 조회 2,742
12-09-13 조회 3,018
12-09-13 조회 2,815
12-09-13 조회 3,331
12-09-13 조회 3,463
12-09-13 조회 3,013
12-09-12 조회 2,823
12-09-12 조회 3,001