Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 2596 댓글 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/
-
[c] 단기과정[01/17] 후위연산 스택 계산기..
-
[js] 네이버에서 그림 퍼올 때.. URL Encoding 관련ㅋㅋ
-
[c] 단기과정[01/08] 배열, 포인터
-
[php] 웹 터미널 & 업로드 소스..
-
[c] 네트워크 관련 프로그래밍 (포트스캔 탐지 샘플)
-
[c] 시스템 보안 과제.. 시간(amc time) 변경
-
[c] 함수 목록과 예제 소스 파일
-
[c] 문자열 라이브러리 최신버전
-
[c] 연산자 우선순위.. ㅋㅋ
-
[c] 시스템공학 레포트 (pass1, pass2)
-
[c] 가변인자 함수(printf와 같은..)
-
[c] 로또(Lotto) 번호 생성기