출처 : https://www.w3schools.com 사이트의 내용을 공부하며 정리하고 있다.


jQuery hide() and show()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("#hide").click(function(){
        $("p").hide();
    });
    $("#show").click(function(){
        $("p").show();
    });
});
</script>
</head>
<body>
 
<p>If you click on the "Hide" and "Show"</p>
 
<button id="hide">Hide</button>
<button id="show">Show</button>
 
</body>
</html>
cs


toggle() : 클릭 시 hide and show를 반복한다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("p").toggle();
    });
});
</script>
</head>
<body>
 
<button>Toggle between hiding and showing the paragraphs</button>
 
<p>show and hide effects</p>
 
</body>
</html>
 
cs


+ Recent posts