Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 2707 댓글 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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
841 | Develop | [vb] 비주얼 베이직 자격증용 ㅎㅎ | hooni | 2003.04.23 | 61506 |
840 | Develop | [vb] 비주얼 베이직 131페이지 | hooni | 2003.04.23 | 58117 |
839 | Develop | [vb] 비주얼 베이직 141페이지 | hooni | 2003.04.23 | 58987 |
838 | Develop | [vb] 비주얼 베이직 173페이지 | hooni | 2003.04.23 | 54875 |
837 | Develop | [vb] 비주얼 베이직 205페이지 | hooni | 2003.04.23 | 56111 |
836 | Develop | [vb] 비주얼 베이직 순위 정렬 루틴 | hooni | 2003.04.23 | 58399 |
835 | Develop | [vb] 비쥬얼 베이직 기출 문제 연습 | hooni | 2003.04.23 | 55198 |
834 | Develop | [vb] 비쥬얼 베이직 기출 문제 연습2 | hooni | 2003.04.23 | 54421 |
833 | Develop | [c] 재미있는 코딩.. | hooni | 2003.04.23 | 21381 |
832 | Develop | [vb] 비쥬얼 베이직으로.. | hooni | 2003.04.23 | 53088 |
831 | Develop | [C] C언어의 조건 연산자(Conditional Operator) | hooni | 2003.04.23 | 14264 |
830 | Develop | [c] 파일입출력 간단한 설명 | hooni | 2003.04.23 | 11261 |