Contents

조회 수 2597 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
825 System/OS [linux] 리눅스 활용 팁^^ hooni 2003.04.23 14630
824 System/OS [linux] 리눅스 파일시스템과 디렉토리 설명 hooni 2013.04.23 26879
823 System/OS [linux] 랜카드가 2개 일 때 네트워크 설정 hooni 2003.04.23 30037
822 System/OS [linux] 랜카드 2개 설정 & iptables 로 사설 ip.. hooni 2003.04.23 14743
821 System/OS [linux] 데스크탑환경(GNOME/KDE) 바꾸기.. hooni 2003.04.23 12104
820 System/OS [linux] 데비안(debian.org) 리눅스 명령어 예제 hooni 2006.04.23 10426
819 System/OS [linux] 네트웍 트래픽 모니터링(MRTG) hooni 2003.04.23 41905
818 System/OS [linux] 네트워크 커널 설정.. hooni 2003.04.23 16482
817 Develop [linux] 날짜나 파일의 내용으로 검색하는 방법(find 명령 사용) hooni 2013.04.23 8123
816 System/OS [linux] 꿀통(honeyd) 설치하기.. 메뉴얼 과정 6 file hooni 2006.04.23 20223
815 System/OS [linux] 기존 환경설정 저장하면서 커널 컴파일.. hooni 2003.04.23 13469
814 System/OS [linux] 기본적인 설정하기(내공쌓기) hooni 2003.04.23 13994
Board Pagination Prev 1 ... 25 26 27 28 29 30 31 32 33 34 ... 98 Next
/ 98