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
번호 분류 제목 글쓴이 날짜 조회 수
217 Develop [js] 사진첩에 쓸 내용 - 마우스 오버로 바꾸기 hooni 2013.04.23 6338
216 Develop [c][php] 프로세스정보와 메모리 정보 웹으로 출력하는거.. file hooni 2013.04.23 6331
215 Develop [java] 에디터.. swing 사용 file hooni 2013.04.23 6300
214 Develop [js] 서서히 나타나는 화면.. ㅋㅋ hooni 2013.04.23 6196
213 Develop [doc] C++언어 문법 설명서 file hooni 2013.04.23 6170
212 Develop [js] 자바스크립트 escape()를 PHP로 받기 hooni 2013.04.23 5990
211 Develop [c] 윈도우 API Viewport와 Window file hooni 2013.04.23 5959
210 Develop [ios] Using protobuf(Protocol Buffers) on iPhone (iOS) file hooni 2014.03.20 4986
209 Develop [PHP] Mac OS에서 PHP 7 설치하기 file hooni 2018.05.11 4889
208 Develop [android] 안드로이드 동영상 스트리밍 예제 2 hooni 2015.01.02 4823
207 Develop [ios] UITableView 특정 Row만 Update hooni 2014.04.08 4780
206 Develop [ios] Objective-C 프로퍼티의 strong, weak, assign file hooni 2014.03.17 4687
Board Pagination Prev 1 ... 48 49 50 51 52 53 54 55 56 57 ... 71 Next
/ 71