Is there any way to check if bubble triggered the click?

后端 未结 5 1520
谎友^
谎友^ 2020-12-24 06:07

Clicking on elements in jQuery causes bubble up to body. If we have a click handler binded to body that shows an alert, then clicking on any element will bubble up to body a

5条回答
  •  孤独总比滥情好
    2020-12-24 06:32

    In React, we can directly get using currentTarget and target

    import React from "react";
    
    function Bar() {
        return (
                
    { if (ev.target == ev.currentTarget) console.log("Target hit"); }} > Click me, maybe
    test doesnt trigger hit
    ); }

提交回复
热议问题