Views 2577 Votes 0 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

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
No. Category Subject Author Date Views
1157 Etc How to completely Uninstall Coda hooni 2017.10.24 2141
1156 System/OS How to Install and Use wget on Mac file hooni 2020.09.03 1277
1155 System/OS How to Setup an Email Server on CentOS 7 hooni 2018.04.05 2779
1154 Develop How to Test SMTP AUTH using Telnet hooni 2018.04.05 1332
1153 System/OS HTTP 프로토콜 (브라우저와 웹서버 간의 통신) hooni 2003.04.23 48250
1152 System/OS HTTPS와 SSL 인증서 file hooni 2014.03.11 7546
1151 Etc iOS 에서 쓸만한 오프라인 구글지도 찾기 hooni 2014.01.06 16035
1150 Etc IoT가 만드는 미래와 플랫폼 경쟁력 secret hooni 2014.09.23 0
1149 Etc IPR 특허 관련 secret hooni 2015.04.28 0
1148 System/OS iptime 공유기 해킹 기술문서 4 file hooni 2015.01.01 1941
1147 Etc ISMS 인증기준 – 정보보호대책 (시스템개발보안) file hooni 2016.12.01 1304
1146 Etc IT감사 기법 시험 file hooni 2017.06.14 1416
1145 Develop JSON, BSON 변환 file hooni 2013.04.23 11814
1144 Develop Laravel 5 Failed opening required bootstrap/../vendor/autoload.php hooni 2018.01.24 1652
1143 System/OS Mac OS X - Apache+PHP+MySQL 환경 서버 hooni 2013.04.25 31627
1142 Develop Mac OS 에 Jenkins 설치하기 (Homebrew) 2 file hooni 2017.03.15 8092
Board Pagination Prev 1 2 3 4 5 ... 74 Next
/ 74