Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 2794 댓글 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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1161 | Develop | [C] C언어의 조건 연산자(Conditional Operator) | hooni | 2003.04.23 | 14282 |
1160 | Develop | [c] 파일입출력 간단한 설명 | hooni | 2003.04.23 | 11275 |
1159 | Develop | [c] home env stack overflow | hooni | 2003.04.23 | 11551 |
1158 | Develop | [c] scanf(), printf() 포맷의 형변환 | hooni | 2003.04.23 | 10898 |
1157 | Develop | [c] CGI Library to C^^ | hooni | 2003.04.23 | 8439 |
1156 | Develop | [c] 간단한 링크드 리스트(linked list) 자료형 예제.. | hooni | 2003.04.23 | 9864 |
1155 | Develop | [php] whois정보 조회 프로그램 | hooni | 2003.04.23 | 11773 |
1154 | Develop | [c] 최대공약수 알고리즘 (유클릿) | hooni | 2003.04.23 | 8908 |
1153 | Develop | [c] 소수점 반올림^^ | hooni | 2003.04.23 | 8500 |
1152 | Develop | [c] 하노이탑 - 재귀함수 | hooni | 2003.04.23 | 9178 |
1151 | Develop | [c] 팩토리얼.. - 재귀함수 | hooni | 2003.04.23 | 9529 |
1150 | Develop | [c] 간단한 채팅(클라이언트/서버) 프로그램 소스 | hooni | 2003.04.23 | 9098 |