Code Snippet to Hide a DIV When User Clicks Outside of it using jQuery

You might have recently experienced that you have to handle clicks in jQuery that occur within a particular webpage but outside a specified region. If yes then read on this post on how to deal with it. In this post on WDJ we present you the jQuery Code to hide a DIV when the user clicks outside of it.

In the below code what you need to understand the most is how event propagation takes place and how it works through the Document Object Model with jQuery to make it simple for your better understanding.

You merely need to add a listener to the html or body element so that if there is any click it will be detected and as soon as it receives the event you hide the box.

So whenever next time the user clicks outside jQuery use the below jQuery Code to Hide DIV:

Image will gone and this text lefts after click

Check out Demo

Recently Published


Is Your Business Site Fully Accessible?

Does your business site have full accessibility? Even with the ADA ...


Secure Web: 5 Best Practices For Application Development

There are several essential best practices for secure web ...


Laravel PHP Framework: Features and benefits for web development

Companies and organizations are focusing on developing custom web ...


Web Development Vs. Software Development: What Is the Difference?

As technology continues to transform all aspects of our lives, a lot ...


Web Redesign : Is Your Landing Page Begging for one?

How do you know when it’s time to web redesign your landing page? ...


Customer Acquisition: Few Steps To Improve This.

Customer acquisition is essential to any business’s success — to ...


Mobile App Development Tools: 5 Enterprise-Ready For Rapid Deployment

There are several enterprise-ready mobile app development tools for ...


Docker: How To Build Better Development Security With It

The top concern among developers and DevOps teams is security within ...


Mobile Development: How to Reduce Costs

Modern markets have become so competitive that it has become vital ...