Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 2742 댓글 0
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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
993 | Develop | How to Test SMTP AUTH using Telnet | hooni | 2018.04.05 | 1577 |
992 | Etc |
IT감사 기법 시험
![]() |
hooni | 2017.06.14 | 1579 |
991 | System/OS | [linux] wget 명령 사용 예제 | hooni | 2020.05.26 | 1583 |
990 | Database |
[mysql] MacOS에 MySQL 설치, 설정, 암호 재설정
![]() |
hooni | 2017.12.15 | 1594 |
989 | Develop | [android] 레이아웃 사이즈 변경 (동적; programmatically) | hooni | 2016.11.07 | 1597 |
988 | System/OS | OpenSSL로 ROOT CA 생성 및 SSL 인증서 발급하기 | hooni | 2017.10.28 | 1616 |
987 | Develop |
[ios] binary를 C코드로 변환
![]() |
hooni | 2015.01.03 | 1634 |
986 | Develop | [ios] 스크린 캡쳐 (전원버튼 + 홈버튼) 호출 알아내기 | hooni | 2014.11.19 | 1647 |
985 | System/OS |
무료로 HTTPS 적용하기 (Let's Encrypt)
![]() |
hooni | 2017.10.28 | 1657 |
984 | System/OS |
[mac] OS X 요세미티 사용자가 많이 겪는 버그와 몇몇 불편사항
![]() |
hooni | 2015.01.04 | 1665 |
983 | Develop | [python] 파라미터 앞에 *, ** 의 의미? (*args, **kwargs) | hooni | 2019.11.22 | 1670 |
982 | Develop | [ios] Swift 4 Singleton inheritance | hooni | 2018.10.31 | 1682 |