Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 2739 댓글 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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
217 | Develop | [ios] NSString 간단한 정규식 사용법 | hooni | 2014.01.28 | 18263 |
216 | Develop | [c] 64bit 머신에서 inet_ntoa() 사용시 Segment fault 대처 방법법 | hooni | 2014.02.08 | 14258 |
215 | Develop | [php] XE 관리자 IP대역 설정 오류 해결법 | hooni | 2014.02.10 | 10815 |
214 | Develop | [html] SVG(Scalable Vector Graphics) 간단 정리 | hooni | 2014.02.13 | 8860 |
213 | Develop | [unix] 로그파일 정리 쉘스크립트 | hooni | 2014.02.19 | 10861 |
212 | Develop | [unix] Java 애플릿용 HTML 자동 생성 | hooni | 2014.02.19 | 8261 |
211 | Develop | [unix] 유닉스 명령에 메타문자 사용 | hooni | 2014.02.19 | 11296 |
210 | Develop | 페이팔에서 돈 찾기 (Paypal withdraw) | hooni | 2014.02.20 | 11460 |
209 | Develop | SVN 명령어 (SVN command) | hooni | 2014.02.28 | 12196 |
208 | Develop | SVN 초간단 사용하기 | hooni | 2014.02.28 | 7674 |
207 | Develop | [ios] URL Scheme 이용하여 앱 설치 확인 | hooni | 2014.03.10 | 4406 |
206 | Develop | [ios] UDID 사용 제한에 따른 대안들 | hooni | 2014.03.13 | 4008 |