Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 2590 댓글 0
Observing show/hide events with jQuery.
HTML Code
<button id="btnShow">Show</button>
<button id="btnHide">Hide</button>
<div class="container">
<div id="foo">
I am #foo
</div>
</div>
<div id="console">
</div>
CSS Code
.container {
height:60px;
margin:10px;
}
#foo {
background-color:#eeeeee;
width:150px;
height:50px;
text-align:center;
font-size:20px;
}
JQuery Code
//The magic code to add show/hide custom event triggers
(function ($) {
$.each(['show', 'hide'], function (i, ev) {
var el = $.fn[ev];
$.fn[ev] = function () {
this.trigger(ev);
return el.apply(this, arguments);
};
});
})(jQuery);
//on Show button click; show the #foo div
$('#btnShow').click(function(){
$('#foo').show();
});
//on Hide button click; hide the #foo div
$('#btnHide').click(function(){
$('#foo').hide();
});
//Add custom handler on show event and print message
$('#foo').on('show', function(){
$('#console').html( $('#console').html() + '#foo is now visible'+ '<br>' )
});
//Add custom handler on hide event and print message
$('#foo').on('hide', function(){
$('#console').html( $('#console').html() + '#foo is hidden'+ '<br>' )
});
[출처] https://www.viralpatel.net/jquery-trigger-custom-event-show-hide-element/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
921 | Develop | [opengl] 컴퓨터 그래픽스 강의 자료(수업자료) | hooni | 2003.04.23 | 20432 |
920 | Develop | [node.js] 지금 하고 있는거.. | hooni | 2013.04.23 | 26979 |
919 | Develop | [node.js] nodejs 기본 설치 | hooni | 2013.04.23 | 26256 |
918 | Etc | [NFC] 단말기와 서버 통신 내용 | hooni | 2013.11.12 | 11193 |
917 | PPT | [network] tcp/ip 설명 html파일 9장(ppt 포함) | hooni | 2013.04.23 | 11650 |
916 | Database | [mysql] 쿼리 실행시 ERROR 1366 (HY000) : incorrect string value : for column 3 | hooni | 2017.03.30 | 8787 |
915 | Database | [mysql] 쿼리 로그 저장 매뉴얼 | hooni | 2013.04.23 | 15218 |
914 | Database | [mysql] 중복데이터 삭제하는 초간단 쿼리 | hooni | 2017.11.22 | 3432 |
913 | Database | [mysql] 접속과 테이블 생성 간단한 설명.. | hooni | 2003.04.23 | 18655 |
912 | Develop | [mysql] 양력, 음력 DB데이터 | hooni | 2013.04.23 | 7802 |
911 | Database | [mysql] 쓰레드가 계속 쌓이기 시작하고 사라지지 않을때.. | hooni | 2003.04.23 | 12787 |
910 | System/OS | [mysql] 시간 관련 SQL구문.. | hooni | 2013.04.23 | 10775 |