Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 64 댓글 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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
834 | Develop | [vim] vim 명령으로  문자 제거하기 (remove 65279 bomb) | hooni | 2021.02.03 | 58 |
» | Develop | [js] show/hide 이벤트 감시 (Observing show/hide event) | hooni | 2021.02.03 | 64 |
832 | Develop |
[swift] popToRoot 모달뷰, 네비게이션컨트롤러 한꺼번에 닫기
![]() |
hooni | 2021.01.29 | 80 |
831 | Develop |
[swift] NotificationCenter 간단 예제
![]() |
hooni | 2021.01.27 | 81 |
830 | Develop | [kotlin] 코틀린 안드로이드 앱 버전/빌드 정보 | hooni | 2020.12.15 | 114 |
829 | Develop | [ubuntu] 우분투 18.04에 PHP5 설치하기 | hooni | 2020.11.14 | 158 |
828 | Develop | [js] Text 값을 클립보드에 복사하기 | hooni | 2020.10.10 | 193 |
827 | Develop | [sh] 쉘스크립트 if 비교 연산 | hooni | 2020.05.26 | 353 |
826 | Develop |
[sh] html 안에 있는 img 다운 받는 쉘 스크립트
![]() |
hooni | 2020.05.26 | 235 |
825 | Develop |
[ios] Start developing your navigation app for CarPlay without enrollment
![]() |
hooni | 2020.02.22 | 462 |
824 | Develop |
[php] 3 Ways to Detect Mobile or Desktop in PHP
![]() |
hooni | 2020.01.28 | 971 |
823 | Develop | 자주 쓰는 Docker 명령어 alias | hooni | 2020.01.10 | 368 |