• 코드:
​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
            // 모든 <button>요소에 mouseenter와 mouseleave 이벤트를 설정함.
11
            $("button").on("mouseenter mouseleave", function() {
12
                $("#text").append("마우스가 버튼 위로 진입하거나 빠져나갔어요!<br>");
13
            });
14
        });
15
    </script>
16
</head>
17
​
18
<body>
19
​
20
    <h1>.on() 메소드</h1>
21
    <button>마우스를 버튼 위로 가져가 보세요!</button>
22
    <p id="text"></p>
23
    
24
</body>
25
​
26
</html>