Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 2772 댓글 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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
721 | Develop | [android] AlertDialog 메시지 창 띄우기 | hooni | 2015.07.09 | 979 |
720 | Develop |
[c] 이진트리/트리 순회법 코드(전위/중위/후위)
5 ![]() |
hooni | 2015.07.02 | 21060 |
719 | Develop |
정리할 자료.
![]() |
hooni | 2015.07.02 | 813 |
718 | Develop | [ios] NSNotificationCenter 초간단 사용 예~ ㅋㄷ | hooni | 2015.06.26 | 753 |
717 | Develop |
[c] 이진 탐색 두 가지 코드 (재귀/반복)
![]() |
hooni | 2015.06.26 | 961 |
716 | Develop |
[c] FSN 온라인 코딩 테스트 (Sorting, Binary Search)
![]() |
hooni | 2015.06.26 | 1126 |
715 | Develop |
[ppt] iOS 플라랩#04(2015.06.19) 발표 자료
![]() |
hooni | 2015.06.04 | 769 |
714 | Develop | Aspect Oriented Programming in Objective-C | hooni | 2015.05.18 | 939 |
713 | Develop | [ios] 설정에서 푸시 알림(APNS) on/off 상태 확인 | hooni | 2015.04.28 | 2154 |
712 | Develop | [ios] GPS 이용 상태 확인 | hooni | 2015.04.27 | 1413 |
711 | Develop | [js] jQuery, Javascript 모바일(스마트폰) 판단하는 방법 | hooni | 2015.04.26 | 2561 |
710 | Develop |
[js] e.stopPropagation() VS e.preventDefault ()
![]() |
hooni | 2015.04.14 | 911 |