수

event.target

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

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,458
jQuery 17-10-11 조회 1,911
jQuery 17-10-11 조회 2,030
jQuery 17-09-29 조회 2,250
jQuery 17-09-29 조회 2,498
jQuery 17-09-29 조회 2,037
jQuery 17-09-26 조회 1,971
jQuery 17-09-26 조회 2,046
jQuery
[jQuery]
17-09-26 조회 1,816
jQuery 17-09-22 조회 2,065
jQuery 17-09-22 조회 2,119
jQuery 17-09-22 조회 2,101
jQuery 17-09-21 조회 2,286
jQuery 17-09-21 조회 2,235
jQuery 17-09-21 조회 2,104
jQuery 17-09-19 조회 2,161
jQuery 17-09-19 조회 1,909
jQuery
[jQuery]
17-09-19 조회 1,900
jQuery
[jQuery]
17-09-18 조회 2,080
jQuery 17-09-18 조회 1,991
jQuery 17-09-18 조회 1,683
jQuery 17-09-14 조회 2,097
jQuery 17-09-14 조회 1,792
jQuery 17-09-14 조회 2,040
jQuery 17-09-11 조회 2,431
jQuery 17-09-11 조회 2,468
jQuery 17-09-11 조회 1,982
jQuery 17-09-10 조회 2,050
jQuery 17-09-10 조회 2,483
jQuery
[jQuery]
17-09-10 조회 1,939