[英]How to get child element that was clicked inside of a component?
我有一個組件正在加載在 html 中加載的第三方腳本。
我試圖檢測何時單擊了注入的 html 元素的特定部分。
基本上:
<div>
<a></a> // detect that this linked was clicked.
</div>
我擁有的:
<Container onClick={(event) => {
event.stopPropagation();
const element = event.currentTarget as HTMLElement;
console.log('EVENT IS', element.ClassName)
}>
// Injected thirdparty html
</Container>
我得到的東西基本上是 Container className 但我想要點擊元素的來源。
我該怎么做呢?
event.currentTarget是附加事件的目標。 使用event.target獲取事件開始的位置。
https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.