I have a child component inside a parent component. I want to to alert message when I click everywhere inside parent except when clicking on child.
class TodoApp extends React.Component {
constructor(props) {
super(props)
this.state = {
}
}
render() {
return (
<div className="parent" onClick={() => alert('x')}>
<p>Alert clicks anywhere on this div</p>
<div className="children">
<button>Do not alert On this element click</button>
</div>
<p>Alert clicks anywhere on this div</p>
</div>
)
}
}
Code example here: