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] 단기과정[01/07] 제어문, 피보나치수열 | hooni | 2003.04.23 | 7439 |
720 | Develop | [c] 단기과정[01/08] 배열, 포인터 | hooni | 2003.04.23 | 7267 |
719 | Develop | [c] 단기과정[01/08] (다차원 + 배열)포인터, void 포인터 | hooni | 2003.04.23 | 7803 |
718 | Develop |
[c] 단기과정[01/08] 과제.. 파스칼 삼각형
![]() |
hooni | 2003.04.23 | 7297 |
717 | Develop |
[c] 단기과정[01/10] 과제.. swap(any data, ..)
![]() |
hooni | 2003.04.23 | 6933 |
716 | Develop |
[c] 단기과정[01/14] 파일 입출력
![]() |
hooni | 2003.04.23 | 6862 |
715 | Develop |
[c] 단기과정[01/14] 피보나치, 파스칼.. 파일입출력
![]() |
hooni | 2003.04.23 | 7115 |
714 | Develop |
[c] 단기과정[01/15] 피보나치, 파스칼.. 링크리스트
![]() |
hooni | 2003.04.23 | 7259 |
713 | Develop |
[c] 단기과정[01/17] 후위연산 스택 계산기..
![]() |
hooni | 2003.04.23 | 7255 |
712 | Develop | [c] 단기과정[01/24] 정렬 알고리즘 | hooni | 2003.04.23 | 6975 |
711 | Develop | [js] 새로고침(refresh)방법과 다른 페이지 바꾸기.. | hooni | 2003.04.23 | 6565 |
710 | Develop | [vbs] CD롬 뱉는 스크립트.. | hooni | 2003.04.23 | 11739 |