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
1157 Develop [iphone] performSelector:withObject:afterDelay: 에 대한 내용 hooni 2013.04.23 65864
1156 Develop [Android] 2010년에 만들었던 세미나 자료. file hooni 2013.05.28 64661
1155 Develop [c#] 간단한 IPC 통신 예제 hooni 2013.04.23 63726
1154 Develop [vb] 비주얼 베이직 자격증용 ㅎㅎ hooni 2003.04.23 61377
1153 Develop [android] Canvas를 이용해 이미지 확대/축소 하기 hooni 2013.04.23 60741
1152 Develop [sh] 쉘스크립트 if 비교 연산 hooni 2020.05.26 59143
1151 Develop [vb] 비주얼 베이직 141페이지 hooni 2003.04.23 58904
1150 Develop [c#] Json 라이브러리 (System.Net.Json.dll) file hooni 2013.04.23 58534
1149 Develop [vb] 비주얼 베이직 순위 정렬 루틴 hooni 2003.04.23 58316
1148 Develop [vb] 비주얼 베이직 131페이지 hooni 2003.04.23 58043
1147 Develop 레고 NXT 마인드스톰 밸런싱 로봇 ㅎㅎ file hooni 2013.04.23 57714
1146 Develop [android] SurfaceView를 이용한 애니메이션 ㅎㅎ file hooni 2013.04.23 57704
1145 Develop [Xcode] 디버깅 옵션 file hooni 2013.04.23 57196
1144 Develop [vb] 비주얼 베이직 205페이지 hooni 2003.04.23 56037
1143 Develop [vb] 비쥬얼 베이직 기출 문제 연습 hooni 2003.04.23 55134
1142 Develop [vb] 비주얼 베이직 173페이지 hooni 2003.04.23 54802
Board Pagination Prev 1 2 3 4 5 ... 74 Next
/ 74