Contents

조회 수 2591 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

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/




?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
705 Develop [ios] APNS, Remote Push 수신 시점에서 앱의 3가지 실행 상태 hooni 2018.10.19 976
704 Develop [ios] APNS에 사용할 인증서 만들기 (KeyChain에 있는 인증서 Export) file hooni 2015.01.03 900
703 Develop [ios] App States file hooni 2013.07.22 13195
702 Develop [ios] Background 에서 네트워크 사용 file hooni 2013.07.22 11510
701 Develop [ios] binary를 C코드로 변환 file hooni 2015.01.03 1533
700 Develop [ios] CoreData 사용하기 (튜토리얼) hooni 2014.03.28 3183
699 Develop [ios] Crashlytics, Fabfic 설치/설정 hooni 2016.07.21 732
698 Develop [ios] DatePicker iOS 6.x 이하 디자인. file hooni 2014.04.10 4062
697 Develop [ios] Debug Extensions (from 종길 차장님 ㅋㅋ) file hooni 2013.04.23 17695
696 Develop [ios] Did UIScrollView End Scrolling? hooni 2016.04.19 1026
695 Develop [ios] DJBros. (DJ요맨~) file hooni 2013.04.23 28104
694 Develop [ios] Facebook Cache 갱신하는 함수 file hooni 2017.02.27 1186
Board Pagination Prev 1 ... 35 36 37 38 39 40 41 42 43 44 ... 98 Next
/ 98