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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
217 | Develop | [js] get방식, url이후 모두 그대로 읽어오기.. | hooni | 2013.04.23 | 6860 |
216 | Develop | [vc++] 게임 소스 등.. ㅋㅋ | hooni | 2013.04.23 | 18384 |
215 | Develop | [c] 격자 직사각형 넓이 구하기 | hooni | 2013.04.23 | 7472 |
214 | Develop | [c] 최단거리 알고리즘 & 예제소스.. 13 | hooni | 2013.04.23 | 10182 |
213 | Develop | [c] vc++ 에서 clrscr(), gotoxy() 함수 사용하기.. | hooni | 2013.04.23 | 14274 |
212 | Develop | [c] 오목.. 간단한 소스 ㅋㅋ | hooni | 2013.04.23 | 9667 |
211 | Develop | [c] 오류체크(CRC 체크 ) 소스 2 | hooni | 2013.04.23 | 8132 |
210 | Develop | [c] 네트워크 정보 알아보기 | hooni | 2013.04.23 | 16145 |
209 | Develop | [c] alarm()함수 설명과 간단한 예제 | hooni | 2013.04.23 | 6701 |
208 | Develop | [c] selec()를 이용한 입출력 다중화 | hooni | 2013.04.23 | 8270 |
207 | Develop | [c] 다중연결 서버 만들기 #4 - thread 사용 | hooni | 2013.04.23 | 23742 |
206 | Develop | [c] 다중연결 서버 만들기 #3 - poll() 사용 | hooni | 2013.04.23 | 6366 |