Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 2802 댓글 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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
721 | Develop | [c++] Win32API를 이용한 ExitWindowsEx 사용한 예제코드 | hooni | 2013.04.23 | 7997 |
720 | Develop |
[c++] Window API(MFC) 오목 게임
![]() |
hooni | 2003.04.23 | 10318 |
719 | Develop |
[c++] WinSock2.0 채팅 프로그램 ㅋㅋ
![]() |
hooni | 2013.04.23 | 8564 |
718 | Develop |
[c++] winsock을 이용한 서버,클라이언트와 ssl서버,클라이언트
![]() |
hooni | 2013.04.23 | 7639 |
717 | Develop |
[c++] 가짜 인증서(하나은행) 프로그램
![]() |
hooni | 2013.04.23 | 10783 |
716 | Develop | [c++] 기초강좌 #01(입출력,영역지정) | hooni | 2003.04.23 | 11474 |
715 | Develop | [c++] 기초강좌 #02(레퍼런스,메모리할당) | hooni | 2003.04.23 | 11482 |
714 | Develop | [c++] 기초강좌 #03(함수의 매개변수 전달) | hooni | 2003.04.23 | 12138 |
713 | Develop | [c++] 기초강좌 #04(클래스) | hooni | 2003.04.23 | 11870 |
712 | Develop |
[c++] 더블 링크리스트(linked list) 학습용 초간단 단어장
![]() |
hooni | 2003.04.23 | 9367 |
711 | Develop |
[c++] 데이터 압축 프로그램 소스 (lzw)
![]() |
hooni | 2013.04.23 | 9971 |
710 | Develop | [c++] 디렉토리 내의 파일 찾기 FindFirstFile() 함수 6 | hooni | 2013.04.23 | 20664 |