Prevent onClick event by clicking on a child div

前端 未结 2 651
醉酒成梦
醉酒成梦 2021-01-14 17:27

I\'m trying to create a modal in React JS

I have one outter div which is the whole body and I have I inner div. I want to apply the function to close the modal if it

相关标签:
2条回答
  • 2021-01-14 18:06

    Attach a function to the inner div which stops propagation.

       function stopPropagation(e) {
          e.stopPropagation();
       }
    

    In your case <div style={this.popupInnerDivStyle()} onClick={stopPropagation}>

    Does this help you: ReactJS SyntheticEvent stopPropagation() only works with React events?

    0 讨论(0)
  • 2021-01-14 18:16

    You could use JS Event.stopPropagation to prevent event from bubbling to the parent if inner element is clicked.

    0 讨论(0)
提交回复
热议问题