Contents

조회 수 2590 댓글 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 [asp] 폼 메일 소스 file hooni 2013.04.23 7353
704 Develop [linux] 임베디드 리눅스 (embedded linux) file hooni 2013.04.23 7356
703 Develop [js] 빈도우즈(bindows96) file hooni 2013.04.23 7368
702 Develop [c] 게임 AI FSM 테스트 샘플 소스.. 꽤 괜찮은 소스.. file hooni 2013.04.23 7370
701 Develop [php] 무조건 다운로드 받도록 header 세팅 file hooni 2013.04.23 7380
700 Develop [c] 농구팀 점수 산출 프로그램 소스 file hooni 2003.04.23 7383
699 Develop [c] 문자열 치환해주는 str_replace() 함수 file hooni 2013.04.23 7385
698 Develop [jsp][php] LDAP 프로그래밍.. file hooni 2003.04.23 7386
697 Develop [c] KNN(K-nearest neighbor) 패턴인식 과제.. file hooni 2013.04.23 7392
696 Develop [c] 시간(요일,날짜 포함) 출력하는 프로그램 초간단 코드 hooni 2013.04.23 7396
695 Develop [c++] mfc로 만든 월플렉스 멀티 수납 시스템(2D기반 설계) file hooni 2013.04.23 7400
694 Develop [c] 단기과정[01/07] 제어문, 피보나치수열 hooni 2003.04.23 7410
Board Pagination Prev 1 ... 35 36 37 38 39 40 41 42 43 44 ... 98 Next
/ 98