jquery 05 mouseenter()와 mouseleave() 메소드

프론트엔드/Jquery|2021. 3. 17. 21:22
Document

마우스 이벤트 알아보기

0

 

 

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  <script>
    var n=0;
    $(document).ready(function() {
      $("div.out").mouseenter(function(){
        $("p:first", this).text("마우스 포인트 들어옴");
        $("p:last", this).text(++n);
      });
      $("div.out").mouseleave(function(){
        $("p:first", this).text("마우스 포인트 나감");
        $("p:last", this).text("최종 횟수: " +n);
      });
    });
  </script>
  <style>
    div.out{
      width: 200px;
      height : 100px;
      border:1px solid #000000;
      text-align: center;
      background-color: yellow;
    }
  </style>
</head>
<body>
  <div class="out">
    <p> 마우스 이벤트 알아보기</p>
    <p>0</p>
  </div>
  
</body>
</html>

댓글()
구독