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 Develop [swift] popToRoot 모달뷰, 네비게이션컨트롤러 한꺼번에 닫기 file hooni 2021.01.29 1379
1156 Develop [swift] NotificationCenter 간단 예제 file hooni 2021.01.27 8109
1155 Develop [kotlin] 코틀린 안드로이드 앱 버전/빌드 정보 hooni 2020.12.15 817
1154 Develop [ubuntu] 우분투 18.04에 PHP5 설치하기 hooni 2020.11.14 938
1153 System/OS [펌] 마이크로서비스, 모노리포, SRE, ... 덮어놓고 구글 따라하면 안 되는 기술들 file hooni 2020.10.15 943
1152 Develop [js] Text 값을 클립보드에 복사하기 hooni 2020.10.10 675
1151 System/OS Apache CORS 설정 1 hooni 2020.09.04 2710
1150 System/OS How to Install and Use wget on Mac file hooni 2020.09.03 1277
1149 System/OS [mac] VirtualBox 실행 스크립트와 bash_profile 설정 file hooni 2020.07.08 954
1148 System/OS [linux] wget 명령 사용 예제 hooni 2020.05.26 1434
1147 System/OS [linux] The Ultimate Wget Download Guide With 15 Awesome Examples hooni 2020.05.26 799
1146 Develop [sh] 쉘스크립트 if 비교 연산 hooni 2020.05.26 59145
1145 Develop [sh] html 안에 있는 img 다운 받는 쉘 스크립트 file hooni 2020.05.26 635
1144 Develop [ios] Start developing your navigation app for CarPlay without enrollment file hooni 2020.02.22 124717
1143 System/OS Configure Postfix to Use Gmail SMTP on Ubuntu 18.04 file hooni 2020.02.07 1248
1142 System/OS RPA란? 어디에 어떻게 쓰이고 누가 만드나? file hooni 2020.01.28 1355
Board Pagination Prev 1 2 3 4 5 ... 74 Next
/ 74