Contents

조회 수 2739 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
477 Develop [c][php] 프로세스정보와 메모리 정보 웹으로 출력하는거.. file hooni 2013.04.23 6337
476 System/OS 아파치(Apache) 인증사용(htaccess)으로 특정 디렉토리에 암호걸기 hooni 2013.04.23 13715
475 Develop [php] 자주 쓰는 PHP 함수와 예제 hooni 2013.04.23 9755
474 Develop [linux] crond 사용법.. ㅋㅋ hooni 2013.04.23 7264
473 Develop [php] 서버 이상 체크 해서 문자보내는 샘플소스.. file hooni 2013.04.23 6710
472 Develop [java] 파일 라인수 계산하는 프로그램 (하위 디렉토리까지..) file hooni 2013.04.23 7650
471 Develop [c] 연산자 우선순위.. ㅋㅋ hooni 2013.04.23 7189
470 Develop [c] 관계형 연산자에 대한 설명 hooni 2013.04.23 7677
469 Develop [c] 게임 AI FSM 테스트 샘플 소스.. 꽤 괜찮은 소스.. file hooni 2013.04.23 7393
468 Develop [c++] 인라인 함수 설명과 예제.. file hooni 2013.04.23 6659
467 Develop [c++] 인라인 함수에 대한 설명 hooni 2013.04.23 7125
466 Develop [c] SetTimer() & KillTimer() & 일회용 Timer hooni 2013.04.23 9222
Board Pagination Prev 1 ... 54 55 56 57 58 59 60 61 62 63 ... 98 Next
/ 98