event.target

· 2017-09-18 (월) 15:53:32 · 1671

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>

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

개발자팁

5,403건

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

+
분류 제목 글쓴이 날짜 조회
jQuery 17-10-11 조회 2,429
jQuery 17-10-11 조회 1,897
jQuery 17-10-11 조회 2,010
jQuery 17-09-29 조회 2,236
jQuery 17-09-29 조회 2,481
jQuery 17-09-29 조회 2,022
jQuery 17-09-26 조회 1,941
jQuery 17-09-26 조회 2,029
jQuery
[jQuery]
17-09-26 조회 1,802
jQuery 17-09-22 조회 2,046
jQuery 17-09-22 조회 2,104
jQuery 17-09-22 조회 2,092
jQuery 17-09-21 조회 2,269
jQuery 17-09-21 조회 2,219
jQuery 17-09-21 조회 2,089
jQuery 17-09-19 조회 2,142
jQuery 17-09-19 조회 1,900
jQuery
[jQuery]
17-09-19 조회 1,882
jQuery
[jQuery]
17-09-18 조회 2,068
jQuery 17-09-18 조회 1,982
jQuery 17-09-18 조회 1,672
jQuery 17-09-14 조회 2,082
jQuery 17-09-14 조회 1,779
jQuery 17-09-14 조회 2,025
jQuery 17-09-11 조회 2,419
jQuery 17-09-11 조회 2,443
jQuery 17-09-11 조회 1,968
jQuery 17-09-10 조회 2,033
jQuery 17-09-10 조회 2,456
jQuery
[jQuery]
17-09-10 조회 1,916