jQuery 수업

jQuery-4(이벤트 hide(), show())

줄라이퍼스트 2020. 2. 19. 10:56

 

<!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) 1초뒤에
                $("p").hide(1000);
            });

            
            $("#show").click(function(){
                // show(speed, callback)
                $("p").show(1000);
            });

        })      

    </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>

</body>
</html>​

 

jQuery hide(), show()  speed 적용

<!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(){
             // id가 hide 것에 대해 클릭을 하면
            $("#hide").click(function(){
                $("p").hide();
            });

            // id가 show것에 대해 클릭을 하면
            // show() = > display : block 같은효과
            $("#show").click(function(){
                // p 태그가 나타남
                $("p").show();
            });

        })      

    </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>

</body>
</html>