Views 2803 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/



?

  1. [Javascript][Ajax] 자바스크립트 강의 산출물

  2. [iphone] 화면 전환 Portrait & Landscape Mode

  3. [iphone] 파일 업로드 샘플 코드 ㅎㅎ

  4. [iphone] 아이폰 어플 모음 ㅋㅋ

  5. [iphone] view에 대한 조사 ㅡ,.ㅡ;

  6. [iphone] performSelector:withObject:afterDelay: 에 대한 내용

  7. [iphone] PerfectlyClear 보정솔루션 최신..

  8. [io] Apple Watch, Today Extension 앱ID 설정

  9. [ios][swift] 초간단 카달로그 앱 (Catalog App)

  10. [ios][swift] 초간단 To-do Memo

  11. [ios][swift] 초간단 TableView 샘플

  12. [ios] 한샘 카달로그 앱 소스 (아이폰용)

  13. [ios] 푸시알림(APNS)에 대한 php 라이브러리 ㅋㅋ

  14. [ios] 패스(path) 앱 메뉴 스타일

  15. [ios] 테이블뷰셀/뷰에 배경 패턴 넣기..

  16. [ios] 코코아 프로그래밍의 네이밍 룰(명명 규칙)

Board Pagination Prev 1 ... 16 17 18 19 20 ... 53 Next
/ 53