JS get the clicked element with event.target

前端 未结 4 464
青春惊慌失措
青春惊慌失措 2021-01-28 13:17

I am trying to use JavaScript to get a clicked element\'s information.

Here is the jsFiddle.

And below is my code.

4条回答
  •  隐瞒了意图╮
    2021-01-28 13:42

    As I wrote in my comment event.target should be fine. But you should be careful if you really only want the p-tags. If you use a-tags or other child elements in the wrapping div you could potentially also receive other tags.

    I'd suggest to actually add the event listener to the p-tags directly.

提交回复
热议问题