Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 2753 댓글 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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
309 | Develop |
[c] 마우스 따라다니는 고양이 - 네코95 (WinAPI)
![]() |
hooni | 2013.04.23 | 7954 |
308 | Develop |
[c] 로또(Lotto) 번호 생성기
![]() |
hooni | 2013.04.23 | 7179 |
307 | Develop |
[c] 레포트용으로 제출했던 여러 소스코드 모음
![]() |
hooni | 2003.04.23 | 8115 |
306 | Develop | [c] 라인수 입력받아 마름모꼴 출력하기.. | hooni | 2003.04.23 | 6897 |
305 | Develop |
[c] 디피-헬만 키교환(Diffie–Hellman key exchange) 샘플 코드.. ㅋㄷ
![]() |
hooni | 2013.04.23 | 9119 |
304 | Develop |
[c] 도스 공격(DoS Attack) 프로그램
![]() |
hooni | 2013.04.23 | 11597 |
303 | Develop |
[c] 도메인(호스트)으로 IP정보 알아오기.. (nslookup과 비슷)
![]() |
hooni | 2013.04.23 | 6941 |
302 | Develop |
[c] 도메인 소켓(Unix Domain Socket) UDP
![]() |
hooni | 2013.04.23 | 9307 |
301 | Develop |
[c] 더블(이중) 연결리스트 예제..
![]() |
hooni | 2013.04.23 | 7475 |
300 | Develop | [c] 달팽이 배열? 인지 먼지.. ㅋㅋ | hooni | 2013.04.23 | 7149 |
299 | Develop |
[c] 단어 입력/수정 프로그램 소스
![]() |
hooni | 2003.04.23 | 7048 |
298 | Develop | [c] 단기과정[01/24] 정렬 알고리즘 | hooni | 2003.04.23 | 6972 |