조회 수 2809 추천 수 0 댓글 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/



?

  1. [js] Text 중 URL 형식을 인식해 단축 URL로 변경

    Date2013.04.23 CategoryDevelop Byhooni Views8732
    Read More
  2. [js] Text 값을 클립보드에 복사하기

    Date2020.10.10 CategoryDevelop Byhooni Views795
    Read More
  3. [js] show/hide 이벤트 감시 (Observing show/hide event)

    Date2021.02.03 CategoryDevelop Byhooni Views2809
    Read More
  4. [js] selectbox 선택 후 input 박스에 적용

    Date2013.04.23 CategoryDevelop Byhooni Views8348
    Read More
  5. [js] php의 number_format() 함수와 같은.. ㅋㅋ

    Date2013.04.23 CategoryDevelop Byhooni Views6953
    Read More
  6. [js] One Time Pad key generatorㅡ.,ㅡ;

    Date2013.04.23 CategoryDevelop Byhooni Views6826
    Read More
  7. [js] JSON 컨트롤.. 재귀호출로 값 출력하기

    Date2013.04.23 CategoryDevelop Byhooni Views28679
    Read More
  8. [js] jQuery, Javascript 모바일(스마트폰) 판단하는 방법

    Date2015.04.26 CategoryDevelop Byhooni Views2571
    Read More
  9. [js] jQuery 코드 작성시 편리한 HTML 템플릿

    Date2013.12.17 CategoryDevelop Byhooni Views33117
    Read More
  10. [js] jQuery 치트 시트

    Date2013.12.18 CategoryDevelop Byhooni Views36303
    Read More
  11. [js] jQuery 충돌 회피

    Date2013.12.17 CategoryDevelop Byhooni Views38376
    Read More
  12. [js] jQuery 셀랙터(selector) 요약

    Date2013.12.17 CategoryDevelop Byhooni Views9440
    Read More
  13. [js] jQuery 셀 병합

    Date2014.09.23 CategoryDevelop Byhooni Views3565
    Read More
  14. [js] jQuery 관련 사이트 링크 모음

    Date2013.04.23 CategoryDevelop Byhooni Views18279
    Read More
  15. [js] jQuery 관련 문서 ㅎㅎ

    Date2013.04.23 CategoryDevelop Byhooni Views31257
    Read More
  16. [js] jQuery plugin 요약

    Date2013.12.20 CategoryDevelop Byhooni Views10753
    Read More
Board Pagination Prev 1 ... 12 13 14 15 16 ... 53 Next
/ 53