html 엘리멘탈 이벤트 문의.
<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에 대해서 어느 정도 안다고 생각하고 있었는데 이런 것도 있군요.
좋은 정보 감사합니다.
좋은 정보 감사합니다.
게시글 목록
| 번호 | 제목 |
|---|---|
| 26447 |
기획서
사이트맵
11
|
| 26436 |
기획서
사이트제작순서 (참고)
10
|
| 5279 | |
| 5276 | |
| 30674 | |
| 18417 |
JavaScript
계층형 카테고리를 여러개 선택할수 있게 하는방법이 없을까요??
|
| 18414 |
jQuery
슬라이드 업 전체메뉴에 대해 질문드립니다.
2
|
| 5261 | |
| 27054 | |
| 5259 | |
| 5239 | |
| 18413 | |
| 31486 |
반응형웹
7. 서버측 반응형 웹 접근방법
17
|
| 18410 | |
| 18400 |
MySQL
mysql like 검색방법
9
|
| 30670 |
웹접근성
웹접근성이란?
3
|
| 5231 | |
| 18395 |
JavaScript
자바스크립트를 이용해서 모바일에 selet 박스 구현한것입니다
4
|
| 18387 |
jQuery
jquery로 펼침 메뉴 입니다.
7
|
| 18381 | |
| 30661 |
웹접근성
웹표준형 화면 확대/축소
8
|
| 5222 | |
| 18380 | |
| 27043 | |
| 18366 |
Mobile
끊기지 않는 세션을 만들려면 어떻게?
13
|
| 24478 | |
| 18359 | |
| 30660 | |
| 18355 |
MySQL
csv 편집 방법?
3
|
| 18351 | |
| 18343 | |
| 18333 | |
| 31439 |
반응형웹
6. 반응형 이미지
46
|
| 18329 |
JavaScript
자바스크립트 해킹 공격에 대한 방어
3
|
| 18323 | |
| 27040 | |
| 30655 | |
| 5211 | |
| 31427 |
반응형웹
잠깐글2. 반응형 테이블
11
|
| 5205 | |
| 5193 | |
| 5184 | |
| 18317 |
jQuery
jQuery Quick Api Reference
5
|
| 27032 | |
| 18313 | |
| 30647 |
CSS
그라디언트 에디터
7
|
| 31408 | |
| 30644 | |
| 18306 | |
| 18303 | |
| 18288 | |
| 27028 | |
| 18285 | |
| 31383 |
반응형웹
5. 반응형 네비게이션/메뉴
24
|
| 27024 | |
| 5174 | |
| 18276 |
Mobile
디바이스별 viewport 설정. (수정본)
8
|
| 27017 | |
| 27130 | |
| 18274 | |
| 26427 | |
| 5170 | |
| 5160 | |
| 5157 | |
| 31371 | |
| 27010 | |
| 18267 | |
| 27003 | |
| 30636 | |
| 18265 | |
| 31350 |
반응형웹
4. 반응형 레이아웃
20
|
| 18262 | |
| 26998 | |
| 18260 |
jQuery
[펌] jQuery select box
1
|
| 26992 | |
| 26988 | |
| 18259 |
기타
구글 확장프로그램 추천
|
| 31328 |
반응형웹
3. 반응형 그리드
21
|
| 26986 | |
| 18257 |
정규표현식
캡쳐 그룹과 비캡쳐 그룹
1
|
| 26983 | |
| 5154 | |
| 26975 | |
| 24474 | |
| 31309 | |
| 26966 | |
| 31251 | |
| 18253 |
웹서버
php 업로드 용량 늘리기
3
|
| 31218 |
반응형웹
반응형 웹 강좌를 시작하며
32
|
| 31201 | |
| 26957 | |
| 26954 | |
| 5147 | |
| 5139 | |
| 18248 | |
| 5132 | |
| 26947 | |
| 31189 | |
| 30631 | |
| 26939 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기