M
M
mynameyourname2016-05-13 19:22:54
JavaScript
mynameyourname, 2016-05-13 19:22:54

How to find out which DOM element the user clicked on?

Suppose there is such a structure

<div ng-click="testClick()">
<div>
<p><span>test</span>
</p>
<ul>
<li><a>test</a>
</li>
</ul>
</div>
</div>

How to find out which nested element was clicked?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Алексей Зуев, 2016-05-13
@mynameyourname

Как обычно - через event.target
И в обработчике используем

function testClick(e) {
  console.log(e.target);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question