event.target

· 8년 전 · 1251

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,580
jQuery
[jQuery]
8년 전 조회 1,465
jQuery 8년 전 조회 1,592
jQuery 8년 전 조회 1,640
jQuery 8년 전 조회 1,657
jQuery 8년 전 조회 1,840
jQuery 8년 전 조회 1,772
jQuery 8년 전 조회 1,635
jQuery 8년 전 조회 1,705
jQuery 8년 전 조회 1,501
jQuery
[jQuery]
8년 전 조회 1,466
jQuery
[jQuery]
8년 전 조회 1,667
jQuery 8년 전 조회 1,554
jQuery 8년 전 조회 1,252
jQuery 8년 전 조회 1,627
jQuery 8년 전 조회 1,370
jQuery 8년 전 조회 1,613
jQuery 8년 전 조회 2,018
jQuery 8년 전 조회 1,992
jQuery 8년 전 조회 1,563
jQuery 8년 전 조회 1,620
jQuery 8년 전 조회 2,017
jQuery
[jQuery]
8년 전 조회 1,519
jQuery
[jQuery]
8년 전 조회 1,435
jQuery 8년 전 조회 2,236
jQuery 8년 전 조회 3,664
PHP 8년 전 조회 5,635
기타 8년 전 조회 1,997
기타 8년 전 조회 1,818
🐛 버그신고