Right now, I just have something that slides open if hovered over, and slides closed if the mouse leaves. I’d like if I could keep it open until someone clicks outside of it.
Ideas?
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.
First just assign a
mouseenterevent so that it opens when you hover:Then place a click event on the document to close it when the user clicks anywhere.
The reason this works is that events bubble from the element that was clicked, up to the root. So placing a
click()event on thedocumentwill catch all clicks on the page, and will close your element.Note that any elements on the page that have a click that does:
or
will cause the bubbling to halt, preventing the handler on the document from firing.