Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
Views 2825 Comment 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/
No. | Category | Subject | Author | Date | Views |
---|---|---|---|---|---|
261 | Database | [mysql] 접속과 테이블 생성 간단한 설명.. | hooni | 2003.04.23 | 18753 |
260 | Database | [mysql] 중복데이터 삭제하는 초간단 쿼리 | hooni | 2017.11.22 | 3574 |
259 | Database | [mysql] 쿼리 로그 저장 매뉴얼 | hooni | 2013.04.23 | 15375 |
258 | Database | [mysql] 쿼리 실행시 ERROR 1366 (HY000) : incorrect string value : for column 3 | hooni | 2017.03.30 | 8985 |
257 | PPT | [network] tcp/ip 설명 html파일 9장(ppt 포함) | hooni | 2013.04.23 | 11694 |
256 | Etc | [NFC] 단말기와 서버 통신 내용 | hooni | 2013.11.12 | 11244 |
255 | Develop | [node.js] nodejs 기본 설치 | hooni | 2013.04.23 | 26328 |
254 | Develop | [node.js] 지금 하고 있는거.. | hooni | 2013.04.23 | 27025 |
253 | Develop | [opengl] 컴퓨터 그래픽스 강의 자료(수업자료) | hooni | 2003.04.23 | 20527 |
252 | Database | [oracle] Oracle 사용자 추가 절차 | hooni | 2019.11.22 | 776 |
251 | Database | [oracle] SQL문 실행 방법 3가지 | hooni | 2013.12.19 | 12203 |
250 | System/OS | [owasp] 10대 웹어플리케이션 보안 취약 | hooni | 2013.04.23 | 16006 |