Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 5560 댓글 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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
313 | Develop |
[c] 메세지 프로그램 (Server - Agent - Client)
![]() |
hooni | 2013.04.23 | 7910 |
312 | Develop |
[c] 맵서치인 듯(옛날 컴에서 찾은 자료)
![]() |
hooni | 2013.04.23 | 8560 |
311 | Develop |
[c] 마우스 따라다니는 고양이 - 네코95 (WinAPI)
![]() |
hooni | 2013.04.23 | 9432 |
310 | Develop |
[c] 로또(Lotto) 번호 생성기
![]() |
hooni | 2013.04.23 | 8279 |
309 | Develop |
[c] 레포트용으로 제출했던 여러 소스코드 모음
![]() |
hooni | 2003.04.23 | 9726 |
308 | Develop | [c] 라인수 입력받아 마름모꼴 출력하기.. | hooni | 2003.04.23 | 8164 |
307 | Develop |
[c] 디피-헬만 키교환(Diffie–Hellman key exchange) 샘플 코드.. ㅋㄷ
![]() |
hooni | 2013.04.23 | 10127 |
306 | Develop |
[c] 도스 공격(DoS Attack) 프로그램
![]() |
hooni | 2013.04.23 | 12362 |
305 | Develop |
[c] 도메인(호스트)으로 IP정보 알아오기.. (nslookup과 비슷)
![]() |
hooni | 2013.04.23 | 8553 |
304 | Develop |
[c] 도메인 소켓(Unix Domain Socket) UDP
![]() |
hooni | 2013.04.23 | 10173 |
303 | Develop |
[c] 더블(이중) 연결리스트 예제..
![]() |
hooni | 2013.04.23 | 8584 |
302 | Develop | [c] 달팽이 배열? 인지 먼지.. ㅋㅋ | hooni | 2013.04.23 | 8336 |