Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 5559 댓글 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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
219 | Develop |
[c#]뉴 툴바 개인적으로 만든거.. (new)
![]() |
hooni | 2013.04.23 | 7724 |
218 | Develop |
[c][php] 프로세스정보와 메모리 정보 웹으로 출력하는거..
![]() |
hooni | 2013.04.23 | 7660 |
217 | Develop |
[c#]업글 뉴 툴바 개인적으로 만든거.. (new) ㅋㅋ
![]() |
hooni | 2013.04.23 | 7651 |
216 | Develop | [android] dp, px 서로 변환 | hooni | 2016.10.21 | 7603 |
215 | Develop | [js] 새로고침(refresh)방법과 다른 페이지 바꾸기.. | hooni | 2003.04.23 | 7602 |
214 | Develop |
[c] 네트워크 보안 프로그래밍 과제 (Server,Agent,Client)
![]() |
hooni | 2013.04.23 | 7601 |
213 | Develop |
[php] 3 Ways to Detect Mobile or Desktop in PHP
![]() |
hooni | 2020.01.28 | 7600 |
212 | Develop |
[java] 채팅창 처럼2.. swing..
![]() |
hooni | 2013.04.23 | 7576 |
211 | Develop |
[c] alarm()함수 설명과 간단한 예제
![]() |
hooni | 2013.04.23 | 7554 |
210 | Develop |
[java] 에디터.. swing 사용
![]() |
hooni | 2013.04.23 | 7504 |
209 | Develop |
[ios] FlckrFeed Example App (Swift)
![]() |
hooni | 2016.11.27 | 7495 |
208 | Develop |
[c] 민수형 소스(도메인소켓포함)
![]() |
hooni | 2013.04.23 | 7490 |