Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 2609 댓글 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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
685 | Develop | [c/c++] Makefile 사용하기.. ㅋㅋ | hooni | 2003.04.23 | 7330 |
684 | Develop | [js] 초간단 암호화/복호화 소스.. | hooni | 2003.04.23 | 8846 |
683 | Develop |
[c]디렉토리 탐색
![]() |
hooni | 2003.04.23 | 7306 |
682 | Develop | [c] 함수 요약 (검색해서 쓰세요..) | hooni | 2003.04.23 | 8799 |
681 | Develop |
[c] 파일(File) 관련 함수 샘플 코드
![]() |
hooni | 2003.04.23 | 7463 |
680 | Develop |
[c] 패스워드 암호화/사용자 정보 보기
![]() |
hooni | 2003.04.23 | 7016 |
679 | Develop |
[c] 파일 복사(copy) 프로그램 샘플 소스
![]() |
hooni | 2003.04.23 | 6772 |
678 | Develop |
[c] UCP/TCP 채팅 소스 - 정리해야 함..
![]() |
hooni | 2003.04.23 | 7917 |
677 | Develop |
[c] IP 스푸핑(ip spoof) 소스 - 정리해야 함
![]() |
hooni | 2003.04.23 | 7549 |
676 | Develop |
[c] 시스템공학 레포트 (pass1, pass2)
![]() |
hooni | 2003.04.23 | 7185 |
675 | Develop |
[c] 레포트용으로 제출했던 여러 소스코드 모음
![]() |
hooni | 2003.04.23 | 8090 |
674 | Develop |
[c] 심심해서.. fseek() 예제..
![]() |
hooni | 2003.04.23 | 7234 |