Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 5572 댓글 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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
265 | Develop |
[c] 네트워크 정보 알아보기
![]() |
hooni | 2013.04.23 | 16971 |
264 | Develop | [c] 메시지큐(Message Queue) 설명.. (joinc) | hooni | 2013.04.23 | 16994 |
263 | Develop |
[ios] APNS 클라이언트 구현 (pdf)
![]() |
hooni | 2013.06.27 | 16995 |
262 | Etc |
[doc] 웜 프레임워크 검증환경 구축(작성중..)
![]() |
hooni | 2013.04.23 | 17047 |
261 | Develop |
[android] 자동차 리모컨 소스코드
![]() |
hooni | 2013.04.23 | 17082 |
260 | Develop | [c++] mfc 기반 레지스트리(registry) 컨트롤 예제 코드 2 | hooni | 2013.04.23 | 17084 |
259 | Database |
[mysql] 쿼리 로그 저장 매뉴얼
![]() |
hooni | 2013.04.23 | 17110 |
258 | System/OS | [linux] 패킷 스니퍼링 | hooni | 2003.04.23 | 17210 |
257 | System/OS | [windows] 원격 데스크탑(터미널 서비스) 포트 변경 | hooni | 2013.04.23 | 17212 |
256 | Etc |
[flash] 페이지 이동 (액션스크립트)
![]() |
hooni | 2013.04.23 | 17241 |
255 | System/OS | [linux] 메타(기호)문자의 의미와 사용 | hooni | 2003.04.23 | 17270 |
254 | Etc | iOS 에서 쓸만한 오프라인 구글지도 찾기 | hooni | 2014.01.06 | 17295 |