• 코드:
​x
 
1
<!DOCTYPE html>
2
<html lang="ko">
3
​
4
<head>
5
    <meta charset="UTF-8">
6
    <title>jQuery Event</title>
7
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
8
    <script>
9
        $(function() {
10
            $("body").on({              // <body>요소에
11
                click: function() {     // click 이벤트가 발생했을 때
12
                    $("#text").html("버튼을 클릭했습니다!");
13
                }
14
            }, "#btn");     // id가 "btn"인 요소에 이벤트 핸들러를 등록함.
15
        });
16
    </script>
17
</head>
18
​
19
<body>
20
​
21
    <h1>이벤트의 연결</h1>
22
    <button id="btn">버튼을 클릭해 보세요!</button>
23
    <p id="text"></p>
24
    
25
</body>
26
​
27
</html>