How to stop propagating event from parent div to child div

前端 未结 5 2021
一向
一向 2021-02-20 01:36

I want to stop propagate event from parent div to child div in my html. Here a simple code what I\'m trying to do:

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-20 01:43

    Check target for match clicked object. Try this code in beginning of click event handler.

    if( event.target !== this ) {
           return;
    }
    //...do stuff.. 
    

提交回复
热议问题