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
549 Develop [ios][swift] 초간단 To-do Memo file hooni 2016.06.27 1061
548 Develop [ios][swift] 초간단 카달로그 앱 (Catalog App) file hooni 2016.06.27 7118
547 Develop [io] Apple Watch, Today Extension 앱ID 설정 hooni 2016.04.20 792
546 Develop [iphone] PerfectlyClear 보정솔루션 최신.. secret hooni 2013.05.28 0
545 Develop [iphone] performSelector:withObject:afterDelay: 에 대한 내용 hooni 2013.04.23 65864
544 Develop [iphone] view에 대한 조사 ㅡ,.ㅡ; file hooni 2013.04.23 54071
543 Develop [iphone] 아이폰 어플 모음 ㅋㅋ secret hooni 2013.04.23 13707
542 Develop [iphone] 파일 업로드 샘플 코드 ㅎㅎ secret hooni 2013.04.23 11120
541 Develop [iphone] 화면 전환 Portrait & Landscape Mode hooni 2013.04.23 22308
540 Develop [Javascript][Ajax] 자바스크립트 강의 산출물 file hooni 2019.10.05 697
539 Develop [java] Interface 와 abstract hooni 2013.04.23 8704
538 Develop [java] netty (비동기 이벤트 방식 네트워크 프레임워크) 사용법 #1 (server) 1 hooni 2015.01.02 2212
537 Develop [java] netty (비동기 이벤트 방식 네트워크 프레임워크) 사용법 #2 (client) hooni 2015.01.02 2037
536 Develop [java] RGB 색상 조절 버튼.. 스윙(swing) file hooni 2013.04.23 7835
535 Develop [java] RGB코드를 HEX코드로 변환하는 코드 ㅎㅎ hooni 2013.04.23 8013
534 Develop [java] Sieve of Eratosthenes (에라토스테네스의 체) hooni 2013.04.23 9337
Board Pagination Prev 1 ... 38 39 40 41 42 ... 74 Next
/ 74