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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
997 | System/OS |
[mac] 맥에서 기본 실행 앱 변경하기
![]() |
hooni | 2018.03.02 | 3890 |
996 | Develop | [ios] Objective-C Types & Storage Capacity | hooni | 2015.07.22 | 3913 |
995 | Develop | [php] mysql_ 과 mysqli_ 의 차이 | hooni | 2017.12.01 | 3914 |
994 | Database |
SQL JOIN 정리 (Inner Join & Outer Join)
![]() |
hooni | 2019.11.22 | 3925 |
993 | Develop | 알고리즘 성능 분석 기준 | hooni | 2014.06.24 | 3980 |
992 | Develop | [ios] Objective-C 프로퍼티의 ATOMIC / NONATOMIC 속성 | hooni | 2014.03.17 | 3993 |
991 | Etc |
영어. 반드시 외워야 할 단어
![]() |
hooni | 2016.07.07 | 3994 |
990 | Develop | [ios] 여러 버전의 Xcode 사용하기 | hooni | 2022.05.28 | 4003 |
989 | System/OS | [linux] wget 명령 사용 예제 | hooni | 2020.05.26 | 4031 |
988 | System/OS |
Enable the Develop Menu in Safari
![]() |
hooni | 2017.02.07 | 4042 |
987 | Develop |
[android] 안드로이드 앱 문서 샘플
![]() |
hooni | 2017.07.11 | 4043 |
986 | PPT |
[ppt] 정보보호관리 발표내용 #2
![]() |
hooni | 2016.12.08 | 4092 |