logo
logo
AI Products 

Close or Hide DIV when clicking outside

avatar
Paritosh Pandey
Close or Hide DIV when clicking outside

In this tutorial, I’m gonna demonstrate you how to track if a click event is being made outside of an HTML element.

Through this example, we are going to close or hide div using Jquery when a click action occurs outside of that element on which the DIV was produced by clicking.

If you have ever found with menus boxes that open on click event, but want them to close when a click event occurs outside of that dom elements.

Here is a simple way to do so.

I’m gonna add an event listener to the document’s body.

When someone clicks it, we look for the event’s targeted id.

collect
0
avatar
Paritosh Pandey
guide
Zupyak is the world’s largest content marketing community, with over 400 000 members and 3 million articles. Explore and get your content discovered.
Read more