Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 2747 댓글 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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
637 | Develop | [c] scanf(), printf() 포맷의 형변환 | hooni | 2003.04.23 | 10875 |
636 | Develop |
[c] selec()를 이용한 입출력 다중화
![]() |
hooni | 2013.04.23 | 8270 |
635 | Develop | [c] SetTimer() & KillTimer() & 일회용 Timer | hooni | 2013.04.23 | 9224 |
634 | Develop |
[c] UCP/TCP 채팅 소스 - 정리해야 함..
![]() |
hooni | 2003.04.23 | 7940 |
633 | Develop | [c] Unix Domain Socket 을 이용한 IPC | hooni | 2013.04.23 | 8032 |
632 | Develop |
[c] UTF-8을 EUC-KR로 변환.. (iconv)
![]() |
hooni | 2013.04.23 | 20175 |
631 | Develop | [c] vc++ 에서 clrscr(), gotoxy() 함수 사용하기.. | hooni | 2013.04.23 | 14275 |
630 | Develop | [c] 가변인자 함수(printf와 같은..) | hooni | 2013.04.23 | 7190 |
629 | Develop |
[c] 가위 바위 보 서버, 클라이언트 소스코드
![]() |
hooni | 2003.04.23 | 8208 |
628 | Develop | [c] 간단한 링크드 리스트(linked list) 자료형 예제.. | hooni | 2003.04.23 | 9860 |
627 | Develop |
[c] 간단한 소켓 프로그래밍 샘플
![]() |
hooni | 2013.04.23 | 8181 |
626 | Develop | [c] 간단한 순위 루틴.. (정보처리기사) | hooni | 2003.04.23 | 6894 |