event.target

· 8년 전 · 1254

event.target


설명 : 이벤트를 시작한 DOM 요소입니다.


이 target속성은 이벤트 또는 그 이벤트의 자손에 대해 등록 된 요소가 될 수 있습니다. 이벤트 버블 링으로 인해 이벤트가 처리되고 있는지를 판별하기 위해 를 비교 event.target하는 것이 종종 유용합니다 this. 이 속성은 이벤트 위임에 매우 유용합니다.


예 :

클릭시 태그 이름 표시


<!doctype html>

<html lang="en">

<head>

  <meta charset="utf-8">

  <title>event.target demo</title>

  <style>

  span, strong, p {

    padding: 8px;

    display: block;

    border: 1px solid #999;

  }

  </style>

  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>

</head>

<body>

 

<div id="log"></div>

<div>

  <p>

    <strong><span>click</span></strong>

  </p>

</div>

 

<script>

$( "body" ).click(function( event ) {

  $( "#log" ).html( "clicked: " + event.target.nodeName );

});

</script>

 

</body>

</html>

|
댓글을 작성하시려면 로그인이 필요합니다. 로그인

개발자팁

개발과 관련된 유용한 정보를 공유하세요. 질문은 QA에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
jQuery 8년 전 조회 1,488
jQuery 8년 전 조회 1,582
jQuery
[jQuery]
8년 전 조회 1,467
jQuery 8년 전 조회 1,596
jQuery 8년 전 조회 1,644
jQuery 8년 전 조회 1,659
jQuery 8년 전 조회 1,845
jQuery 8년 전 조회 1,776
jQuery 8년 전 조회 1,638
jQuery 8년 전 조회 1,708
jQuery 8년 전 조회 1,505
jQuery
[jQuery]
8년 전 조회 1,469
jQuery
[jQuery]
8년 전 조회 1,670
jQuery 8년 전 조회 1,556
jQuery 8년 전 조회 1,255
jQuery 8년 전 조회 1,628
jQuery 8년 전 조회 1,373
jQuery 8년 전 조회 1,615
jQuery 8년 전 조회 2,020
jQuery 8년 전 조회 1,993
jQuery 8년 전 조회 1,565
jQuery 8년 전 조회 1,625
jQuery 8년 전 조회 2,018
jQuery
[jQuery]
8년 전 조회 1,521
jQuery
[jQuery]
8년 전 조회 1,438
jQuery 8년 전 조회 2,238
jQuery 8년 전 조회 3,668
PHP 8년 전 조회 5,637
기타 8년 전 조회 2,000
기타 8년 전 조회 1,820
🐛 버그신고