Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 5571 댓글 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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
709 | Develop |
[c] 암호화 알고리즘 DES 구현 ㅋㅋ
![]() |
hooni | 2013.04.23 | 8557 |
708 | Develop |
[c] KNN(K-nearest neighbor) 패턴인식 과제..
![]() |
hooni | 2013.04.23 | 8564 |
707 | Develop |
[c] 맵서치인 듯(옛날 컴에서 찾은 자료)
![]() |
hooni | 2013.04.23 | 8565 |
706 | Develop |
[ajax] 이벤트 코드 생성기 작업중.. ㅋㅋ
![]() |
hooni | 2013.04.23 | 8567 |
705 | Develop |
[c] 무선 Radius Server 자료..
![]() |
hooni | 2013.04.23 | 8568 |
704 | Develop |
[c] 플러드 필링 (flood filling) 알고리즘..
![]() |
hooni | 2013.04.23 | 8570 |
703 | Develop |
[c] 더블(이중) 연결리스트 예제..
![]() |
hooni | 2013.04.23 | 8585 |
702 | Develop |
[c] 텍스트 파일(로그)을 정해진 라인 단위로 쪼개주는 코드
![]() |
hooni | 2013.04.23 | 8586 |
701 | Develop |
[c] 문자열 str_shift 예제..
![]() |
hooni | 2013.04.23 | 8591 |
700 | Develop |
[java] 파일 라인수 계산하는 프로그램 (하위 디렉토리까지..)
![]() |
hooni | 2013.04.23 | 8597 |
699 | Develop |
[chm] 비주얼 C++ 팁 모음 문서
![]() |
hooni | 2013.04.23 | 8597 |
698 | Develop |
[c] 심심해서.. fseek() 예제..
![]() |
hooni | 2003.04.23 | 8616 |