<div id="example" style="background:yellow;height:200px;width:200px;">
<button>Some text</button>
</div>
I want #example to .hide when it’s clicked, but I don’t want it to .hide when it’s child elements get clicked.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Add a handler to the
<div>and then check if it’s the target.In this example, the
event.targetis the element that was actually clicked, butthisis the element attached with the handler.