- jQuery-4에서는 hide(), show()를 썻는데 이것보다는 toggle()를 사용하는 것을 추천합니다.
toggle()는 hide(), show()를 번갈아 가면서 실행을 합니다.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#hide").click(function(){
// hide(speed, callback)
$("p").hide(1000);
});
$("#show").click(function(){
// show(speed, callback)
$("p").show(1000);
});
$("#toggle").click(function(){
// hide와 show를 번갈아 실행
$("h3").toggle();
});
});
</script>
</head>
<body>
<p>If you click on the "Hide" button, I will disappear.</p>
<button id="hide">Hide</button>
<button id="show">Show</button>
<button id="toggle">Toggle</button>
<h3>This is h3</h3>
<h3>This is another h3</h3>
<h3>This is 3rd h3</h3>
</body>
</html>
※ 실행화면
'jQuery 수업' 카테고리의 다른 글
jQuery-7(이벤트 slideUp(), slideDown()) (0) | 2020.02.19 |
---|---|
jQuery-6(이벤트 fadeIn(), fadeOut(), fadeTo(), fadeToggle()) (0) | 2020.02.19 |
jQuery-4(이벤트 hide(), show()) (0) | 2020.02.19 |
jQuery-3(마우스 이벤트, mouseenter, mouseleave, mousedown, mouseup) (0) | 2020.02.19 |
jQuery-2(더블클릭) (0) | 2020.02.19 |