1. toggle메소드 사용하기
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;" charset="utf-8" >
<title> toggle method </title>
<script src="http://code.jquery.com/jquery-1.7.2.js"></script>
<style type="text/css">
.hidden{display:none;}
</style>
<script>
$(document).ready(function (){
//.toggle(fn1, fn2); //fn1과 fn2를 서로 토글링 한다.
$('#btn').toggle(
function(){$('#myLayer').addClass('hidden');},
function(){$('#myLayer').removeClass('hidden');}
);
});
</script>
</head>
<body>
<h1>버튼을 클릭할 때마다 레이어 보이기/숨기기</h1>
<input id="btn" type="button" value="button" />
<div id="myLayer" style="background-color:yellow;">
Hello!
</div>
</body>
</html>
2. toggle메소드 사용하기(css 클래스에 대한 토글링)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;" charset="utf-8" >
<title> toggleClass()메소드로 css클래스에 대한 toggle </title>
<script src="http://code.jquery.com/jquery-1.7.2.js"></script>
<style type="text/css">
.hidden{display:none;}
</style>
<script>
$(document).ready(function (){
$('#btn').click(function (){
//hidden CSS Class에 대해서 addClass()<->removeClass()
$('#myLayer').toggleClass('hidden');
});
});
</script>
</head>
<body>
<h1>버튼을 클릭할 때마다 레이어 보이기/숨기기</h1>
<input id="btn" type="button" value="button" />
<div id="myLayer" style="background-color:yellow;">
Hello!
</div>
</body>
</html>
'강좌 > jQuery' 카테고리의 다른 글
제이쿼리(jQuery) - each() 메서드 (0) | 2013.04.22 |
---|---|
제이쿼리(jQuery) - css() 메서드와 콜백함수(CallBack) (0) | 2013.04.22 |
제이쿼리(jQuery) - filter()와 slice() 메서드. (0) | 2013.04.22 |
제이쿼리(jQuery) - addClass()와 removeClass() (0) | 2013.04.20 |
제이쿼리(jQuery) - Selector (선택기 / 선택자) 전반적인 내용 (0) | 2013.04.16 |